19 April 2025

Dr.Mario Controller

The Dr. Mario controller we have made includes five inputs. Moving the joystick or spatula left or right will move the pill in the game left or right. Lifting the controller from a horizontal position to a vertical position with the wire sticking out at the top will move the pill down faster, moving the controller horizontal again will return the speed to its normal rate. Spinning the dial or pill clockwise will do the same in the game and counter-clockwise will turn in counter-clockwise. The goal of the controller was to make the controls logical while the original controls such as the B and A buttons might not translate to a player that they are going to rotate the pill. The motions are meant to replicate a person using a pill counting tray such as using a spatula to move and count them and lifting the tray to pour them into a bottle. The reasoning for a pill counting tray metaphor rather than objects like a stethoscope is that it fits the pills and doctor theme better and is shaped more like a controller. The controller affords some lack of knowledge of the game but does not afford players having small hand sizes.

Does this controller feel more in theme than a regular NES controller? How can we improve its shape?

Contributions:

  • Karlie has worked on the design, pseudo code, base code, controller container, wiring, and writing. 
  • Christopher has worked on the coding, controller container, schematic, wiring, photo, and recording. 


#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Adafruit_seesaw.h>
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>

// Pin Definitions
#define SEESAW_ADDR          0x36
Adafruit_seesaw ss;
int32_t encoder_position;
int leanPin = A3; // JOYSTICK

// Variables
int previousSpinVal = 0; //track the spin direction
const int rotationThreshold = 5; // Threshold for spin detection
const int deadZone = 10; // Dead zone to prevent noise-triggered actions

void setup() {
  Serial.begin(9600);

  Keyboard.begin();
  CircuitPlayground.begin();
  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);

  if (!ss.begin(SEESAW_ADDR)) {
    Serial.println("Couldn't find seesaw on default address");
    while(1) delay(10);
  }
  Serial.println("seesaw started");

  // get starting position
  encoder_position = ss.getEncoderPosition();
  Serial.println("Turning on interrupts");
  delay(10);
  ss.enableEncoderInterrupt();
}

void loop() {
  if (digitalRead(CPLAY_SLIDESWITCHPIN) == HIGH) {
    int32_t new_position = ss.getEncoderPosition();
    if (encoder_position != new_position) {
      Serial.println(new_position); // display new position
    }
    if (encoder_position < new_position) {
      Keyboard.press('x'); // Simulate clockwise spin
      Serial.println("Clockwise Spin");
    }
    if (encoder_position > new_position) {
      Keyboard.press('z'); // Simulate counterclockwise spin
      Serial.println("Counterclockwise Spin");
    }
    if (encoder_position == new_position) {
      Keyboard.release('x'); // No spin
      Keyboard.release('z');
    }
    encoder_position = new_position;

    // Handle lean direction
    int leanVal = analogRead(leanPin); // I moved this down

    // **Added Serial Output for LeanVal**
    Serial.print("Lean Value: ");
    Serial.println(leanVal);

    if (leanVal < 341) { // Lean left
      Keyboard.press(KEY_LEFT_ARROW);
      Serial.println("Lean: Left");
    } else if (leanVal > 682) { // Lean right
      Keyboard.press(KEY_RIGHT_ARROW);
      Serial.println("Lean: Right");
    } else { // No lean
      Keyboard.release(KEY_LEFT_ARROW);
      Keyboard.release(KEY_RIGHT_ARROW);
    }

    // Handling Accelerometer - Y axis
    float yValue = CircuitPlayground.motionY();
    Serial.print("Y-axis value: ");
    Serial.println(yValue);

    if (yValue >= 2) {
      Keyboard.press(KEY_DOWN_ARROW);
      Serial.println("Down arrow key pressed");
    } else {
      Keyboard.release(KEY_DOWN_ARROW);
    }

    delay(300); // Short delay for readability
  } else {
    Keyboard.releaseAll(); // Release all pressed keys when switch is OFF
  }
}




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.