Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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/
- */
- #include <Esplora.h>
- boolean buttonStates[8];
- const byte buttons[] = {
- JOYSTICK_DOWN,
- JOYSTICK_LEFT,
- JOYSTICK_UP,
- JOYSTICK_RIGHT,
- SWITCH_RIGHT, // pause
- SWITCH_LEFT, // attack
- SWITCH_UP, // BUG!
- SWITCH_DOWN // BUG!
- };
- const char keystrokes[] = {
- KEY_DOWN_ARROW,
- KEY_LEFT_ARROW,
- KEY_UP_ARROW,
- KEY_RIGHT_ARROW,
- KEY_ESC,
- 'x',
- KEY_UP_ARROW,
- KEY_DOWN_ARROW
- };
- void setup() {
- Keyboard.begin();
- }
- void loop() {
- for (byte thisButton=0; thisButton<8; thisButton++) {
- boolean lastState = buttonStates[thisButton];
- boolean newState = Esplora.readButton(buttons[thisButton]);
- int loudness = constrain(Esplora.readMicrophone(), 200, 1023);
- int furyAttack = map(loudness, 0, 1023, 0, 10);
- if(furyAttack > 3){
- Keyboard.press('c');
- Esplora.writeGreen(100);
- }
- else{
- Keyboard.release('c');
- Esplora.writeGreen(0);
- }
- if (lastState != newState) {
- if (newState == PRESSED) {
- Keyboard.press(keystrokes[thisButton]);
- }
- else if (newState == RELEASED) {
- Keyboard.release(keystrokes[thisButton]);
- }
- }
- buttonStates[thisButton] = newState;
- }
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment