18 April 2021

Project: Game Controller | Microphone Controller for Friday Night Funkin'

 


For this project I made a controller for the game Friday Night Funkin'. It's a rhythm game, similar to DDR where you press the corresponding key when it reaches the top bar. Normally this would be done by pressing the W, A, S, and D or Arrow Keys but for this controller you just tilt the microphone in the direction of the arrow on screen. I chose a microphone for the housing of my controller as the game is very much about music and even uses a microphone similar to this one for some of it's logos. As far as gameplay goes, it's fairly straight forward. The player simply tilts the microphone in the correct direction at the correct time. The player must return to "zero" or back to a vertical position before making another input. The significance of this controller's appearance pertains to the relationship between rhythm/music and microphones/movement. The controller takes input through the accelerometer in the CPE and maps that motion in the X and Y directions to a threshold that is constantly checked. If the threshold is reached in a certain direction, it's respective input is triggered.

Question: One of the things I wanted to add was to use the on board microphone of the CPE as an input, but I couldn't come up with any logical use for this. What could I have used the microphone for?





CODE:

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

 
/*
Code by Austin Owens
---------------------------------------
Alternative Controller for Friday Night Funkin'
*/


//initiate variables 
bool xPressed;
bool yPressed;
int xOut;
int yOut;

void setup() {

  Serial.begin(9600);
  Keyboard.begin(); 
  CircuitPlayground.begin();
}

void loop() {

  float x = CircuitPlayground.motionX(); //Gets motion in X direction (A D)
  float y = CircuitPlayground.motionY(); //Gets motion in X direction (W S)

//Maps motion output to an integer
  xOut = map(x, -10, 10, -10, 10);
  yOut = map(y, -10, 10, -10, 10);

//Debugging
  Serial.print(x);
  Serial.println(y);
  
//When the controller is tilted past the threshold, executes the code
    switch(xOut) {
      case -9 :
        if(!xPressed) { //checks for spam prevention
          Keyboard.write('A');
          xPressed = true; //sets spam prevention true until controller returns to "zero"
        }
        break;
      case 9 :
        if(!xPressed) {
          Keyboard.write('D');
          xPressed = true;
        }
        break;
      case 0 : xPressed = false; //resets spam prevention when the controller returns to straight "zero" position
        break;
    }
    
    switch(yOut) {
      case -9 :
        if(!yPressed) {
          Keyboard.write('S');
          yPressed = true;
        }
        break;
      case 9 :
        if(!yPressed) {
          Keyboard.write('W');
          yPressed = true;
        }
        break;
      case 0 : yPressed = false;
        break;
    }
}




No comments:

Post a Comment

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