bubdan

Pedro Kicks Back

May 24th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. /*
  2. this is a sketch for the esplora that goes with a game I found and like on boyslife.org: http://boyslife.org/games/online-games/30016/pedro-kicks-back/
  3. */
  4.  
  5. #include <Esplora.h>
  6. boolean buttonStates[8];
  7. const byte buttons[] = {
  8.   JOYSTICK_DOWN,
  9.   JOYSTICK_LEFT,
  10.   JOYSTICK_UP,
  11.   JOYSTICK_RIGHT,
  12.   SWITCH_RIGHT, // pause
  13.   SWITCH_LEFT, // attack
  14.   SWITCH_UP, // BUG!
  15.   SWITCH_DOWN // BUG!
  16. };
  17. const char keystrokes[] = {
  18.   KEY_DOWN_ARROW,
  19.   KEY_LEFT_ARROW,
  20.   KEY_UP_ARROW,
  21.   KEY_RIGHT_ARROW,
  22.   KEY_ESC,
  23.   'x',
  24.   KEY_UP_ARROW,
  25.   KEY_DOWN_ARROW
  26. };
  27. void setup() {
  28.   Keyboard.begin();
  29. }
  30. void loop() {
  31.   for (byte thisButton=0; thisButton<8; thisButton++) {
  32.     boolean lastState = buttonStates[thisButton];
  33.     boolean newState = Esplora.readButton(buttons[thisButton]);
  34.       int loudness = constrain(Esplora.readMicrophone(), 200, 1023);
  35.   int furyAttack = map(loudness, 0, 1023, 0, 10);
  36.  if(furyAttack > 3){
  37.   Keyboard.press('c');
  38.   Esplora.writeGreen(100);
  39.  }
  40.  else{
  41.    Keyboard.release('c');
  42.    Esplora.writeGreen(0);
  43.  }
  44.     if (lastState != newState) {
  45.       if (newState == PRESSED) {
  46.         Keyboard.press(keystrokes[thisButton]);
  47.       }
  48.       else if (newState == RELEASED) {
  49.         Keyboard.release(keystrokes[thisButton]);
  50.       }
  51.     }
  52.     buttonStates[thisButton] = newState;
  53.   }
  54.   delay(50);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment