18 April 2021

Friday Night Funkin Game Controller

The original design for my game controller was made with the intention of using four separate PIR motion sensors in conjunction with the Circuit Playground Express. However, during the construction of the controller, I realized there were hardware inconsistencies and thus that idea was shelved. This final design uses only two of the PIR motion sensors in addition to a potentiometer. The conceptual model was designed to resemble the arrows of Friday Night Funkin. I used a thermoplastic called Worbla in order to create a sturdy shape for the arrows. These were created before discovering the hardware issues but I decided to use three of the arrows in the end. The signifiers of this design were the arrows allowing the user to easily identify which direction the sensor would correspond to. The feedback is that the user can see the corresponding arrows pressed on-screen while the relevant motion is applied to the sensors and potentiometer. The input and output mapping are as follows: The potentiometer, when turned counterclockwise, will output a left arrow or the “A” key. When turned clockwise the output will be the right arrow or the “D” key. The two motion sensors will output the up and down arrows or the “W” and “S” keys respectively. The affordances are the four input mechanics the user has access to. All other components are hidden.

Do you think this design is too confusing given the use of containers meant for the previously intended hardware?



#include <Keyboard.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>


int pirState = LOW;

int pirState2 = LOW; // we start, assuming no motion detected

int val = 0;      // variable for reading the pin status

int val2 = 0;

boolean rightPressed = false;

boolean leftPressed = false;


int potenNum = 0;

int potenMap = 0;


void setup() {

  pinMode(3, INPUT);

  pinMode(2, INPUT);

  Serial.begin(9600);

  Keyboard.begin();

}

 

void loop(){

  val = digitalRead(3);  // read input value

  val2 = digitalRead(2);  // read input value


  potenNum = analogRead(A1);

  //Serial.print(potenNum);

  

  // The position of the potentiometer is mapped to a value to determine left or right

  potenMap = map(potenNum, 0, 1023, 0, 10);


  // Press Left Arrow

  if(potenMap == 10){

    //Serial.println(potenMap);

    Keyboard.press(216);

    leftPressed = true;


  }

   // Press Right Arrow

  if(potenMap == 0){

    //Serial.println(potenMap);

    Keyboard.press(215);

    rightPressed = true;

  }

  // Release Right Arrow

  if(potenMap != 0 && rightPressed == true){

    Keyboard.release(215);

    rightPressed = false;

  }


  // Release left arrow

  if(potenMap != 10 && leftPressed == true){

    Keyboard.release(216); 

    leftPressed = false;

  }

  // check if the input is HIGH (MOTION!!!)

  if (val == HIGH) {            

    // Press Up Arrow

    if (pirState == LOW) {

      // we have just turned on the up key

      Keyboard.press(218);

      Serial.println("Motion 1 detected!");

      pirState = HIGH;

    }

  } else if ((val == LOW)) {

    if (pirState == HIGH){

      // we have just turned off the up key

      Keyboard.release(218);

      Serial.println("Motion 1 ended!");

      pirState = LOW;

    }

  }

  

   // check if the input is HIGH (MOTION!!!)

   if (val2 == HIGH) {

    // Press Down Arrow

    if (pirState2 == LOW) {

      // we have just turned on the down key

      Keyboard.press(217);

      Serial.println("Motion 2 detected!");

      pirState2 = HIGH;

    }

  } else if ((val2 == LOW)) {

    if (pirState2 == HIGH){

      // we have just turned off the down key

      Keyboard.release(217);

      Serial.println("Motion 2 ended!");

      pirState2 = LOW;

    }

  }

}

Friday Night Funkin' Game Controller

 




My controller was designed to play a rythm game known as "Friday Night Funkin'". When I first started thinking of how to code it I thought to myself, "It'd be cool if you could play it with tilt controls." So that's what I aimed to do. I made it so that when you tilted the remote upwards it would input the "W" key which is up in the game, downwards was "S" key which was down in the game, right was the "D" key which is right in the game, and left was the "A" key which was left in the game. After I finished doing that through a lot of trial and error, especially with choosing how long I should delay each input (if I should at all) to hit the note that I had to hold down and then making it reset (aka using the Keyboard.releaseAll() function) when the CPE was being held upright and completely horizontal, took me some time. After I did that I wanted to do more so I said what if I made it so I thought "What if I used a potentiometer to control the volume of the game?" The game uses "+" and "-" keys to control the volume but raising it and lowering it respectfully. I tried to do that but at the end of the day I couldnt get the potentiometer to work so I scrapped the idea. The next thing I thought would be funny was what if when you yell it selects something on the menu (presses the "SPACE" key) after many tries, that space key worked in every other game and program but this one, but I kept it in because I found it neat for other games. The last thing I did, and most inconvenient thing to learn, was programming the light sensor to detect when your finger was on top of it (when the light value turned to 0) and to then press the "ESC" key. I tried to make it so that I could navigate the menus without the keyboard and "ESC" allowed me to go backwards. Turns out the tissue box I used is very dark so that value of 0 is constantly being detected which means "ESC" was being pressed every second, and arduino (that I know of) can't press 2 keys at once, so I couldn't play the game when the sensor detected darkness. To fix this, instead of completely scrapping it, for some reason, I put my phone's flashlight on and put it on top of the CPE which kept the light value higher than 0. To press "ESC" all I had to do was remove the phone's flashlight. At that point I decided that was enough and that's how I made my controller. 

My question would be:
Should I remove the light sensor feature or change it to do something else?

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

const int Second = 1000;
const int mSecond = 100;

const int dark = 0;

int light;

float sound;
float loud = 105;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  CircuitPlayground.begin();
  Keyboard.begin();
}

void loop() {
  // put your main code here, to run repeatedly:

  //Get values of accelerometer, assign each value to each arrow key on the keyboard
  
  //data on xAxis
  float xAxis = CircuitPlayground.motionX();
  Serial.print(xAxis);
  Serial.print("\t");

  //data on yAxis
  float yAxis = CircuitPlayground.motionY();
  Serial.print(yAxis);
  Serial.print("\t");


  if (yAxis >= 6) {
    Keyboard.press('s');
    delay(mSecond);
  } else {
    Keyboard.releaseAll();
  }

   if (xAxis >= 6) {
    Keyboard.press('a');
    delay(mSecond);
  } else {
    Keyboard.releaseAll();
  }

   if (yAxis <= -6) {
    Keyboard.press('w');
    delay(mSecond);
  } else {
    Keyboard.releaseAll();
  }

   if (xAxis <= -6) {
    Keyboard.press('d');
    delay(mSecond);
  } else {
    Keyboard.releaseAll();
  }

  if (xAxis > -6 && xAxis < 6 && yAxis > -6 && yAxis < 6) {
    Keyboard.releaseAll();
    delay(mSecond);
  }
  
  
  //Get value of light senor, if light value is darker than a certain value, input "esc" on the keyboard.

  light = CircuitPlayground.lightSensor();
  
  Serial.print("Light Sensor: ");
  Serial.println(light);

    if (light <= dark) {
    Keyboard.press(KEY_ESC);
    Serial.println("esc");
    delay(mSecond);
    Keyboard.release(KEY_ESC);
    delay(Second);
 
  }


  //Get value of sound sensor, whenever the value hits a big number that is equivalent to a scream or loud blow, press space

  sound = CircuitPlayground.mic.soundPressureLevel(10);
  
  Serial.print("Sound Sensor SPL: ");
  Serial.println(sound);

  if (sound >= loud) {
    Keyboard.write(' ');
    Serial.println("SPACE");
    delay(Second);
  }

  
}


Marble Ball Controller Final


The controller was intended to primarily rely on an orb for movement since the player

will be able to consciously understand how to move and forward.

Moving left to right however was a challenge to get functioning. Ideally, especially with this game,

sliding the ball left and right would be the best thing to do for optimal conveyance.

However complications with the soft pot hindered this idea thus leading to the idea of using tilt controls.

This idea was inspired by the Monkey Ball games where moving left and right would tilt the camera,

creating the illusion the the stage itself was moving.

This same idea was applied to jumping, in which tilting the controller upward will simulate

the action of jumping. Obvious constraints for how far the player can slide the ball left and right needed to be considered as well. The controller relies on the rotary encoder to simulate forward and backwards moving by reading

the 2 bit output of the encoder. This meant that the encoder wasn't analog, the encoder would only

output the bits based on which way it was rotated. This was enough though since keyboard inputs

didn't need to be analog. Ideally the fast the user rolls the ball the faster the player would go.

So simply calling the encoder function more often when the encoder was rotating was sufficient.

Since keyboard input could be treated as digital input for this game accelerometers could be treated

as such as well by giving the inputs rotation  threshold to reach to output a key output.

To help provide feedback for some of the controls, the CPE lights up to covey which tilt input was

last read. Feedback for moving the ball forward seemed unnecessary due to it being the most

active part of the controller demanding the most attention of the player. All this helps simulate

the experience rolling a marble, with some conveniences to help traversal through obstacles

manageable



#include <Keyboard.h> #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> int encoderPin1 = A2; //pin for encoder bit reading int encoderPin2 = A3; //pin for encoder bit reading volatile int lastEncoded = 0; volatile long encoderValue = 0; volatile long tempValue = 0; long lastencoderValue = 0; int lastMSB = 0; int lastLSB = 0; void setup() { CircuitPlayground.begin(); pinMode(encoderPin1, INPUT); pinMode(encoderPin2, INPUT); digitalWrite(encoderPin1, HIGH); //turn pin resistor on digitalWrite(encoderPin2, HIGH); //turn pin resistor on Serial.begin (9600); } void loop(){ float controllerX = CircuitPlayground.motionX(); float controllerZ = CircuitPlayground.motionZ(); //checks for right accelerometer tilt for right output if(controllerX >= 5 && digitalRead(CPLAY_SLIDESWITCHPIN)) { Keyboard.press(215); //change color CircuitPlayground.setPixelColor(9,10,30,50); CircuitPlayground.setPixelColor(8,10,30,50); CircuitPlayground.setPixelColor(7,10,30,50); CircuitPlayground.setPixelColor(6,10,30,50); CircuitPlayground.setPixelColor(5,10,30,50); CircuitPlayground.setPixelColor(4,10,30,50); CircuitPlayground.setPixelColor(3,10,30,50); CircuitPlayground.setPixelColor(2,10,30,50); CircuitPlayground.setPixelColor(1,10,30,50); } //checks for left accelerometer tilt for left output else if(controllerX <= -5 && digitalRead(CPLAY_SLIDESWITCHPIN)) { Keyboard.press(216); //change color CircuitPlayground.setPixelColor(9,100,30,50); CircuitPlayground.setPixelColor(8,100,30,50); CircuitPlayground.setPixelColor(7,100,30,50); CircuitPlayground.setPixelColor(6,100,30,50); CircuitPlayground.setPixelColor(5,100,30,50); CircuitPlayground.setPixelColor(4,100,30,50); CircuitPlayground.setPixelColor(3,100,30,50); CircuitPlayground.setPixelColor(2,100,30,50); CircuitPlayground.setPixelColor(1,100,30,50); } //release all press keys when controller is flat. else { Keyboard.releaseAll(); } //jump key checking if(controllerZ <= 7 && digitalRead(CPLAY_SLIDESWITCHPIN)) { Keyboard.write('z'); Serial.println("jump pressed"); } //detecting encoder rotation if(digitalRead(encoderPin1) == 0 || digitalRead(encoderPin2) == 0) { updateEncoder(); } delay(10); } void updateEncoder(){ int MSB = digitalRead(encoderPin1); //MSB = most significant bit int LSB = digitalRead(encoderPin2); //LSB = least significant bit Serial.println("Function called"); int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number int sum = (lastEncoded << 2) | encoded; //adding it to the previous encoded value if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) { Keyboard.press(218); encoderValue++; } if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) { Keyboard.press(217); encoderValue--; } lastEncoded = encoded; //store this value for next time }


   

Pac-Man Game Controller

The project that I created is a game controller for one of the most well known games in the world, Pac-Man. As we all know Pac-Man is a classic among classics and it needs no introduction but just in case you somehow haven’t played Pac-Man, it is very simple. You simply use the directional arrow keys to direct the Pac-Man so that he can eat all the pellets in the level while avoiding the ghosts so you don’t lose a life. Unless of course, you happen to gobble up the big fruit which turns all the ghosts blue and allows the Pac-Man to eat them too, sending them back to their cage in the center to be redeployed and buying you some more time. For this project, I made a Pac-Man themed game pad that the player can use instead of those small pesky arrow keys. I figured it might be more fun and engaging for the player to tilt my game pad for movement than it would be to use the traditional method of movement. I also wanted to make my game pad intuitive so that any player could pick it up, take one look at it, and know exactly how to use it. I have drawn some arrows in each direction and a joystick in the center in order to convey to the player that they need to tilt the game pad in the direction they want to go just like they would with a joystick. I have also added some Pac-Man themed art to give the game pad that extra touch so that the player can feel like they are using something made especially for Pac-Man and nothing else. My one question for the audience would be which game do you think would have been better suited to this game controller, if any? Why?



    CODE

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

const int Time = 100;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  CircuitPlayground.begin();
  Keyboard.begin();
}

void loop() {
  // put your main code here, to run repeatedly:

  //data on xAxis
  float horizontal = CircuitPlayground.motionX();
  Serial.print(horizontal);
  Serial.print("\t");

  //Debugging tools for the Y Axis values
  float vertical = CircuitPlayground.motionY();
  Serial.print(vertical);
  Serial.print("\t");


  if (vertical >= 4) {
    Keyboard.write(217);
    delay(Time);
  }

   if (horizontal >= 4) {
    Keyboard.write(216);
    delay(Time);
  }

   if (vertical <= -4) {
    Keyboard.write(218);
    delay(Time);
  }

   if (horizontal <= -4) {
    Keyboard.write(215);
    delay(Time);
 }
}




VIDEO WAS TOO LARGE, HAD TO UPLOAD TO YOUTUBE.

LINK: https://youtu.be/VgmAdEhYlYc 



Vecter - Gryo Band - Game Controller


    My controller is for a game called Vecter. It is a runner-shooter arcade style game with a simple premise: drive forward, and don’t run into obstacles.



    With my controller, I want to turn the player's hand into the hovercraft that you play as. As this is a fast-paced game, mapping should be intuitive and feedback should instantaneous. The design resembles the in-game ship to reinforce this idea. You should be able to put on the controller a quickly learn how it operates. If you understand how a quad-copter or helicopter moves. It's should be obvious how to operate the device. As you tilt you hand to the side, the ship on-screen tilts simultaneously as it leans into a strafe. Tilting forward, like that of a quad-copter, causes you to accelerate. Lean further to boost. As a gesture-based device, the signifiers are a combination of prior knowledge and immediate on-screen feedback. With strong, obvious, mapping the player should quickly be able to develop the muscle memory to use the device at a high level. While looking at the controller is opposite the goal, there is some additional feedback for strafing where only the NeoPixels on the corresponding side will light up. The is a visual design feature alone.

    I’ve primarily utilized the CPE’s accelerometer to detect the x and y axis of your hand and mapped various tilting angles to the correlating inputs (WASD keyboard-only format.) Tilting left or right makes the vehicle strafe left or right ('a' and 'd.') In Vecter, rarely do you want to stop accelerating, so I made acceleration ('w') toggle on upon tilting forward for the first time, which only toggles off when tilting back to brake. This allows you to keep your hand in a more comfortable position while still playing the game optimally. Tilting further forward will activate a boost ('ctrl'.) And lastly, pinch you fingers to continuously fire ('space.')

Question:

I believe the mapping is intuitive enough to not require directions, and that one could figure out how the controller works in a few minutes of play. However, there is some innate bias since I already know all the functions well. Are there any elements of the controller's functions that should be signified on the controller itself?


Schematic:


Code:

/* 
 *  Custom Controller Final Project
 *  Gyro Band - Cameron Friday
*/

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

//pin used for shooting control
const int shootPin = A6;
int i = 0;

void setup() {
  //Initialize CPE and Keyboard output
  Serial.begin(9600);
  CircuitPlayground.begin();
  Keyboard.begin();
  
  //read shooting pin
  pinMode(shootPin, OUTPUT);
  digitalWrite(shootPin, HIGH);

  //Startup animation
  for(i = 0; i < 10; i++)
    {
      CircuitPlayground.setPixelColor(i, 82, 15, 82);
      delay(200);
    }
  delay(1000);
}

void loop() {
  //read accelerometer x and y
  float x = CircuitPlayground.motionX();
  float y = CircuitPlayground.motionY();
  Serial.print(x);
  Serial.print("\t");
  Serial.println(y);

  //set shooting if connection made
  if(digitalRead(shootPin) == LOW)
  {
    Keyboard.press(' ');
  }
  else
  {
    Keyboard.release(' ');
  }

  
  ////GYRO CONTROLS BELOW////

  //Strafe Right//
  if(x <= -4)
  {
    Keyboard.press('d');
    //light up right side Neopixels only
    CircuitPlayground.setPixelColor(0, 0, 0, 0);
    CircuitPlayground.setPixelColor(1, 0, 0, 0);
    CircuitPlayground.setPixelColor(2, 0, 0, 0);
    CircuitPlayground.setPixelColor(3, 0, 0, 0);
    CircuitPlayground.setPixelColor(4, 0, 0, 0);
    CircuitPlayground.setPixelColor(5, 82, 15, 82);
    CircuitPlayground.setPixelColor(6, 82, 15, 82);
    CircuitPlayground.setPixelColor(7, 82, 15, 82);
    CircuitPlayground.setPixelColor(8, 82, 15, 82);
    CircuitPlayground.setPixelColor(9, 82, 15, 82);
  }

  //Strafe Left//
  if(x >= 4)
  {
    Keyboard.press('a');
    //light up left side Neopixels only
    CircuitPlayground.setPixelColor(0, 82, 15, 82);
    CircuitPlayground.setPixelColor(1, 82, 15, 82);
    CircuitPlayground.setPixelColor(2, 82, 15, 82);
    CircuitPlayground.setPixelColor(3, 82, 15, 82);
    CircuitPlayground.setPixelColor(4, 82, 15, 82);
    CircuitPlayground.setPixelColor(5, 0, 0, 0);
    CircuitPlayground.setPixelColor(6, 0, 0, 0);
    CircuitPlayground.setPixelColor(7, 0, 0, 0);
    CircuitPlayground.setPixelColor(8, 0, 0, 0);
    CircuitPlayground.setPixelColor(9, 0, 0, 0);  
  }

  //Brake if tilting backwards//
  if (y >= 4)
  {
    Keyboard.press('s');
    //toggle off acceleration
    Keyboard.release('w');
    CircuitPlayground.clearPixels();
  }
  
  //Accelerate if tilting forward//
  if (y <= -4)
  {
    //toggle on acceleration
    Keyboard.press('w');
  }

  //Boost ONCE if far forward//
  if (y <= -7)
  {
    Keyboard.write(KEY_LEFT_CTRL);
  }
  
  //Neutral X Axis//
  if ((x > -4) && (x < 4))
  {
    Keyboard.release('d');
    Keyboard.release('a');
    //all Neopixels lit
    CircuitPlayground.setPixelColor(0, 82, 15, 82);
    CircuitPlayground.setPixelColor(1, 82, 15, 82);
    CircuitPlayground.setPixelColor(2, 82, 15, 82);
    CircuitPlayground.setPixelColor(3, 82, 15, 82);
    CircuitPlayground.setPixelColor(4, 82, 15, 82);
    CircuitPlayground.setPixelColor(5, 82, 15, 82);
    CircuitPlayground.setPixelColor(6, 82, 15, 82);
    CircuitPlayground.setPixelColor(7, 82, 15, 82);
    CircuitPlayground.setPixelColor(8, 82, 15, 82);
    CircuitPlayground.setPixelColor(9, 82, 15, 82);
  }
  
  //Neutral Y Axis//
  if ((y > -4) && (y < 4))
  {
    Keyboard.release('s');
  }
}

Superflight Controller


My controller is for the game Superflight a game with procedurally generated maps, simple controls, and relaxing. My controller is based around the real-life sport of Hang gliding, the game is based around a wingsuit, close to a glider. The controller has a long white bar with two gloves attached to each side, in the middle of the bar is a box and a Circuit Playground Express is attached to the bar in the box. The idea of the controller was to Improve immersion within the game. The game has 4 controls: A, S, W, D. I also added a capacitive sensor as a space bar to navigate the menu, I used a white wire for this.  The controls for the game all use the Circuit Playground Express to go forward, back, and side to side. X is mapped to right and left and y is mapped to forward and backward. After making and implementing this controller I found that the game lost one aspect and gained another, the game became way less Zen and way more intense. Before having to only use three fingers, using your whole upper body is a drastic change in how you play the game. 

In what could I change the box that holds the CPE to improve the experience for the user? 


#include <Keyboard.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

#include <math.h>

 

const int debounce = 30;

const int threshold = 500;

 

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9200);

  while(!Serial);

  CircuitPlayground.begin();

  Keyboard.begin();

}

 

void loop() {

  // put your main code here, to run repeatedly:

  //read accelerometer x and y

  float x = CircuitPlayground.motionX();

  float y = CircuitPlayground.motionY();

//go right

if(x < -3) {

Keyboard.write('D');

delay(debounce);

}

//go left

if(x > 3) {

Keyboard.write('A');

delay(debounce);

}

//go foward

if(y < -3) {

Keyboard.write('W');

delay(debounce);

}

//go back

if(y > 3) {

Keyboard.write('S');

delay(debounce);

}

 

if(CircuitPlayground.readCap(A1) > threshold ) {

Keyboard.write(' ');

delay(debounce);

}

}







 

Downwell Controller

 




https://store.steampowered.com/app/360740/Downwell/

    For the game Downwell, I made a controller setup that matches the player’s actions almost directly to what the character in the game does. I included a wearable accelerometer to measure the player’s tilt and a force resistor to detect if the player is on the ground or not. The container housing the accelerometer is attached to the back of a vest that the player wears. When the player tilts to either the left or the right by a certain amount, a left or right arrow key is pressed and held respectively until the player returns to a neutral position. Leaning forward is mapped to the escape key, which pauses the game and opens the menu. The force resistor is under a pad that the player stands on and is inert when the player is standing on it, but when the force on the sensor is less than a certain amount, meaning the player has jumped off of it, the space key is pressed to make the character jump.

    Feedback happens very quickly in the game because the player doesn’t have to move too much to have their input registered. The controls are also intuitive for the player because all they have to do is move in the same way they want the character to move. If they lean left and jump, the character will jump and move to the left as well. This also means that the response time of the character is limited by the user’s own physical ability and reaction time. In this regard, the game may become limiting for some people and have a higher barrier of entry. The input for the escape key is less obvious, and I missed the opportunity to create a good signifier for it. However, considering it isn’t as important as the other controls, it doesn’t limit the player’s affordances too much.

    The idea behind this controller was to make the player feel like they were a more active participant in the game. Now they have to struggle with the character. Downwell is a game where the player is constantly fighting against the force of gravity pulling them down. By making the player jump in real life, this struggle is made much more tangible.

Do you think there's a more intuitive way to access the escape key than leaning forward using the setup that I've created?


//Chris Tillis

//Game Controller
//libraries 

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

//Global Variables
int sideThresh = 4;
int frontThresh = -3;
int jumpThresh = 600;
float sideTilt = 0;
float frontTilt = 0;
int fsrReading; 

//Timekeeping Variables
unsigned long currentTime;
unsigned long jumpTime;
unsigned long menuTime; 

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    delay(10000);
    CircuitPlayground.begin();
    Keyboard.begin();
} 

//Main Loop
void loop() { 

  //Time variable updated
  currentTime = millis(); 

  //All sensor input gathered
  sideTilt = CircuitPlayground.motionX();
  frontTilt = CircuitPlayground.motionY();
  fsrReading = analogRead(A7); 

  //Space bar pressed when FSR has no weight
  if(fsrReading < jumpThresh && currentTime - jumpTime > 100){
    Keyboard.press(' ');
    jumpTime = currentTime;
    Serial.println("jump"); 

  } //If not currently jumping, press escape if player leans forward
  else if(frontTilt > frontThresh && currentTime - menuTime > 5000){
    Keyboard.write(177);
    menuTime = currentTime;                                                                                
    Serial.println("escape");
  } 

  //Press right when player leans right, release when not leaning
  if(sideTilt > sideThresh){
    Keyboard.press(215);
    Serial.println("right");
  }
  else
    Keyboard.release(215); 

  //Press left when player leans left, release when not leaning
  if(sideTilt < -(sideThresh)){
    Keyboard.press(216);
    Serial.println("left");
  }
  else
    Keyboard.release(216); 

  //Jump is released after .5 seconds
  if(currentTime - jumpTime > 500)
    Keyboard.release(' '); 
}