Skip to content

Instantly share code, notes, and snippets.

@annem
Created January 29, 2013 01:15
Show Gist options
  • Save annem/4660843 to your computer and use it in GitHub Desktop.
Save annem/4660843 to your computer and use it in GitHub Desktop.
// include Esplora library functions
#include <Esplora.h>
// declare variables used to store sensor data
int hammer;
int left;
// setup() block
// All lines in between { and } are part of the setup block, and run once, at the beginning
void setup() {
Serial.begin(9600); // open serial port - used for observing data
Keyboard.begin(); // turn Esplora into a keyboard
}
void loop() {
// Store SWITCH4 data in hammer variable
// Store JOYSTICK_LEFT data in left variable
// ** Add lines required for right, up and down. Don't forget to declare variables in top lines!
hammer = Esplora.readButton(SWITCH_4);
left = Esplora.readButton(JOYSTICK_LEFT);
// if/else statement - maps SWITCH4 press to keyboard spacebar press
if (hammer == 0){
Keyboard.press(' ');
delay(100);
}
else{
Keyboard.release(' ');
delay(100);
}
// **** Add if/else statements required to map right, left, up, and down joystick movements to
// **** left, right, up, and down keyboard presses... almost identical to hammer if/else above.
// Print data to Serial Monitor... this is very helpful for debugging when
// something doesn't work.
// *** Add right, up, and down to serial monitor output.
Serial.print(hammer);
Serial.print('\t'); // prints a tab in between variables
Serial.println(left);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment