26 November 2023

Shoe Controller for Sonic the Hedgehog

 

My controller was meant to emulate a shoe that Sonic would wear in the video game and control him using logic that would be attributed to it. The mappings are the accelerometer tilt and proximity sensor lifting to get the feedback of running left and right as well as jumping. The signifiers rely heavily on knowing that lifting the shoe towards the front will move him in the default forward direction and that lifting up would make sense to the user for an input to jump. The design affords an inconspicuous look in theory but with the parts being so hard to fit into a small shoe it can get out of hand as seen in the picture of the final design. My big question is if it would be better to use a bigger shoe or some other method to hide the wiring inside the controller?


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

int trigPin=A3; // proximity sensor output obtained at this pin
int echoPin=A1;
int a=0;   //just a variable to check the current value of sensePin
const int debounce = 100;
bool flag = true;
void setup() {
  // put your setup code here, to run once:
  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP); // Switch as to turn on
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  Serial.begin(9600); // For debug
  Keyboard.begin();
  delay(1000); // delay 1 second
  CircuitPlayground.begin(); // Initialize CPE
  // define gyroscope and proximity sensor
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(CPLAY_SLIDESWITCHPIN)){
    long duration, distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration * .0343) /2;
    float y = CircuitPlayground.motionY(); // Y motion

    if(y >= 6){ // include if statement for gyroscope detecting right movement
      Keyboard.press(215); //moves right
      delay(debounce);
    } else {
      Keyboard.release(215);
    }
    if(y <= -6){ // include if statement for gyroscope detecting left movement
      Keyboard.press(216); //moves left
      delay(debounce);
    } else {
      Keyboard.release(216);
    }
    if(distance > 5 && distance < 7 && flag == true) {
 Keyboard.press('s');
 Keyboard.release('s');//do soemthing once
 delay(debounce);
 Serial.print("in range");
flag = false;
}
if(distance >= 400 || distance <= 0) { //out of range
flag = true;
Serial.print("out of range");
}
  }
 
}



No comments:

Post a Comment

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