22 October 2023

Pan's Flute Controller - DeMunck

 



PAN'S FLUTE

Taking inspiration from Crypt of the Necrodancer's musical and high fantasy theming, I decided to go ahead with making the pan flute my alternative controller for this game. Each pipe, when blown into, plays a different note and controls a different directional key + combination of directional keys used to play the game (as the game is played solely using the WASD keys on the keyboard). The pan flute will use a microphone to detect sound input and determine what note is being played on the flute, therefore determining which directional key is “pressed” at the moment. In keeping with the fantasy theming, I decided I wanted to aesthetically model this controller after the Grecian, Pan (who the instrument is named after), and use actual wooden pipes etched with flowers and leaves and a bound with a green rope, so as to reference his connection with nature and fertility.



PSEUDOCODE

1) #include standard Circuit Playground libraries, #include Keyboard.h

2) Declare variable for sound value to be received through microphone, named soundValue

3) Initialize keyboard in setup

4) Serial.begin(9600); for allowing communication between the CircuitBoard and the Serial Monitor

5) Create new functions: troubleshoot() and controlDirection(float soundValue)

5a) troubleshoot() will contain code that sends messages to the Serial Monitor concerning sound input and other debugging messages via Serial.print() and Serial.println()

5b) controlDirection(float soundValue) detects the soundValue using CircuitPlayground.micsoundPressureLevel() and, then, based on that value, determines which direction the player moves in by writing to the keyboard using this dictionary as reference: https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers/

6) ex:

void moveDirection () {

  soundValue = CircuitPlayground.mic.soundPressureLevel(x);

  if (soundValue >= 10) {

    Keyboard.write(KEY_UP_ARROW);

  }

}

6a) the x value is equivalent to the number of milliseconds it takes to determine the soundValue

No comments:

Post a Comment

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