Teensy LC soldering error- teensyduino fix?
Posted: Sun May 08, 2016 9:13 pm
Hi there,
I just finished soldering all the pcb wires into my teensy LC, and realized I accidentally skipped GPIO 0, and started from 1. Thus, all of the pin positions are shifted over one space, so instead 0-11 it goes from 1-12. Rather than re solder back everything one space, I'm thinking I'd prefer to update the provided code to reflect the new wired positions in the Teensy. I'm new to the teensyduino library and thus their commands in the arduino IDE so I could use some help.
I figured I'd just have to alter the setupkeys function, but so far the gamepad doesn't work. Here's the code so far:
I'm sure i'm missing something, though. Any ideas? Or should I just re solder all the wires back into their intended spaces?
I just finished soldering all the pcb wires into my teensy LC, and realized I accidentally skipped GPIO 0, and started from 1. Thus, all of the pin positions are shifted over one space, so instead 0-11 it goes from 1-12. Rather than re solder back everything one space, I'm thinking I'd prefer to update the provided code to reflect the new wired positions in the Teensy. I'm new to the teensyduino library and thus their commands in the arduino IDE so I could use some help.
I figured I'd just have to alter the setupkeys function, but so far the gamepad doesn't work. Here's the code so far:
Code: Select all
#include <Bounce.h>
#define NUM_KEYS 12
struct Key {
char keycode;
Bounce* bounce;
};
Key keys[NUM_KEYS];
Key key(char keycode, int pin) {
Key *ret = new Key;
ret->keycode = keycode;
ret->bounce = new Bounce(pin, 10);
pinMode(pin, INPUT_PULLUP);
return *ret;
}
void setupKeys() {
keys[1] = key('w', 1);
keys[2] = key('s', 2);
keys[3] = key('a', 3);
keys[4] = key('d', 4);
keys[5] = key('p', 5);
keys[6] = key('l', 6);
keys[7] = key('o', 7);
keys[8] = key('k', 8);
keys[9] = key('x', 9);
keys[10] = key('z', 10);
keys[11] = key('q',11);
keys[12] = key('e',12);
}
void setup() {
setupKeys();
Keyboard.begin();
// pinMode(0, INPUT_PULLUP);
}
void loop() {
for (int i = 0; i < NUM_KEYS; i++) {
keys[i].bounce->update();
if (keys[i].bounce->fallingEdge()) {
Keyboard.press(keys[i].keycode);
} else if (keys[i].bounce->risingEdge()) {
Keyboard.release(keys[i].keycode);
}
}
}