Page 1 of 1
Additional buttons on GB0
Posted: Fri May 27, 2016 12:32 pm
by Jimanez11
I was thinking about adding a few more buttons on to the gameboy shell (I got a bag of 100 tactile switches and might as well use a few) to have dedicated buttons for saving / loading games. Have already soldered them in series and glued them in exactly like the right and left buttons in the back case, but the teensy isn't recognizing them for some reason. I have added two additional lines into the code wermy provided, but they wont take. Any suggestions or additional lines of code that would need to be included? I also skipped a few connections on the teensy and wired these into ports 15 and 16.
Re: Additional buttons on GB0
Posted: Fri May 27, 2016 12:44 pm
by wermy
Can you post what your teensy code looks like now?
Re: Additional buttons on GB0
Posted: Fri May 27, 2016 12:54 pm
by Jimanez11
Sure thing! Thanks again for the quick reply. The code is below:
#include <Bounce.h>
#define NUM_KEYS 14
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[0] = key('w', 0);
keys[1] = key('s', 1);
keys[2] = key('d', 2);
keys[3] = key('a', 3);
keys[4] = key('p', 4);
keys[5] = key('k', 5);
keys[6] = key('o', 6);
keys[7] = key('x', 7);
keys[8] = key('z', 8);
keys[9] = key('l', 9);
keys[10] = key('e', 10);
keys[11] = key('q', 11);
keys[15] = key('c', 15);
keys[16] = key('v', 16);
}
void setup() {
setupKeys();
Keyboard.begin();
// pinMode(0, INPUT_PULLUP);
}
void loop() {
for (int i = 0; i < NUM_KEYS; i++) {
keys.bounce->update();
if (keys.bounce->fallingEdge()) {
Keyboard.press(keys.keycode);
} else if (keys.bounce->risingEdge()) {
Keyboard.release(keys.keycode);
}
}
}
Re: Additional buttons on GB0
Posted: Fri May 27, 2016 1:12 pm
by wermy
Looks like it should work. :\ Dumb question but you do have the new buttons connected to the same ground as the other ones, right?
Re: Additional buttons on GB0
Posted: Fri May 27, 2016 1:14 pm
by wermy
Never mind I see it. Change this:
keys[15] = key('c', 15);
keys[16] = key('v', 16);
To this:
keys[12] = key('c', 15);
keys[13] = key('v', 16);
That number in the bracket is an array index, not a pin number. That should fix it!

Re: Additional buttons on GB0
Posted: Fri May 27, 2016 2:20 pm
by Jimanez11
Worked like a charm!!! Thanks!

Re: Additional buttons on GB0
Posted: Fri May 27, 2016 3:21 pm
by LoafSlice
@Wermy
Am I missing a thread for coding the pi and teensy?
Re: Additional buttons on GB0
Posted: Fri May 27, 2016 4:36 pm
by wermy
LoafSlice wrote:@Wermy
Am I missing a thread for coding the pi and teensy?
I go over that in the second part of the guide:
http://sudomod.com/game-boy-zero-guide-part-2/
There is some code posted there for making the teensy act like a keyboard. At some point I'll post a second piece of code for making it show up as a USB game pad in stead.
Re: Additional buttons on GB0
Posted: Fri May 27, 2016 5:57 pm
by LoafSlice
wermy wrote:LoafSlice wrote:@Wermy
Am I missing a thread for coding the pi and teensy?
I go over that in the second part of the guide:
http://sudomod.com/game-boy-zero-guide-part-2/
There is some code posted there for making the teensy act like a keyboard. At some point I'll post a second piece of code for making it show up as a USB game pad in stead.
would this be of any use to me adding a joystick? as well as the d pad and the xyab and the L and R?