Skip to content

Instantly share code, notes, and snippets.

@bernhardberger
Created July 1, 2015 21:12
Show Gist options
  • Save bernhardberger/176e61ed95a772cf88ce to your computer and use it in GitHub Desktop.
Save bernhardberger/176e61ed95a772cf88ce to your computer and use it in GitHub Desktop.
teensy 3.1 quick sketch 32 buttons no pullup
// the buttons in the gamecontroller will be in that order.
// first button in array.. button#1, second button, button#2 etc.
// if you need to skip a button set the value "-1"
const int buttonPins[] = {
11, // Button 1 | Paddle Shift Down
19, // Button 2 | Paddle Shift Up
-1, // Button 3 | ------------------
5, // Button 4 | Exit
7, // Button 5 | Up
9, // Button 6 | Down
10, // Button 7 | Pit Limiter
14, // Button 8 | minus 1
15, // Button 9 | Okay/Enter
16, // Button 10 | Prev
17, // Button 11 | Next
18, // Button 12 | Push to talk
};
void setup() {
Joystick.useManualSend(true);
Joystick.hat(-1); // disable hat switch
// set up pullup for buttons
for (int i = 0; i < (sizeof(buttonPins)/sizeof(int)); i++) {
if (buttonPins[i] > 0) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
}
void loop() {
updateButtons();
Joystick.send_now();
delay(5); // 5ms sleep, runs at 200Hz. Should be fairly enough
}
void updateButtons() {
for (int i = 0; i < (sizeof(buttonPins)/sizeof(int)); i++) {
if (buttonPins[i] > 0) {
Joystick.button(i+1, digitalRead(buttonPins[i]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment