Skip to content

Instantly share code, notes, and snippets.

@galennare
Created February 18, 2018 02:39
Show Gist options
  • Save galennare/e7fb31a49d3e6f93fb3e4364a4c43375 to your computer and use it in GitHub Desktop.
Save galennare/e7fb31a49d3e6f93fb3e4364a4c43375 to your computer and use it in GitHub Desktop.
Arduino Program for an Esplora board to play N64 games on an emulator. Upload, install mupen64, and play.
#include <Esplora.h>
#include <Keyboard.h>
boolean buttonStates[4];
const byte buttons[] = {
SWITCH_RIGHT,
SWITCH_LEFT,
SWITCH_UP,
SWITCH_DOWN
};
const char keystrokes[] = {129, 'X', 'Z', 128};
// Button 1 is B, Button 2 is L, Button 3 is Z, and button 4 is A
void setup() {
Keyboard.begin();
}
void loop() {
for (byte thisButton = 0; thisButton < 4; thisButton++) {
boolean lastState = buttonStates[thisButton];
boolean newState = Esplora.readButton(buttons[thisButton]);
if (lastState != newState) {
if (newState == PRESSED) {
Keyboard.press(keystrokes[thisButton]);
}
else if (newState == RELEASED) {
Keyboard.release(keystrokes[thisButton]);
}
}
buttonStates[thisButton] = newState;
}
// Analog to digital joystick with a 25% deadzone
if (Esplora.readJoystickY() > 127) {
Keyboard.press(217);
} else {
Keyboard.release(217);
}
if (Esplora.readJoystickY() < -127) {
Keyboard.press(218);
} else {
Keyboard.release(218);
}
if (Esplora.readJoystickX() > 127) {
Keyboard.press(216);
} else {
Keyboard.release(216);
}
if (Esplora.readJoystickX() < -127) {
Keyboard.press(215);
} else {
Keyboard.release(215);
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment