Additional buttons on GB0
Additional buttons on GB0
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.
- wermy
- Site Admin
- Posts: 1346
- Joined: Tue May 03, 2016 8:51 pm
- Has thanked: 620 times
- Been thanked: 1322 times
- Contact:
Re: Additional buttons on GB0
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);
}
}
}
#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);
}
}
}
- wermy
- Site Admin
- Posts: 1346
- Joined: Tue May 03, 2016 8:51 pm
- Has thanked: 620 times
- Been thanked: 1322 times
- Contact:
Re: Additional buttons on GB0
Looks like it should work. :\ Dumb question but you do have the new buttons connected to the same ground as the other ones, right?
- wermy
- Site Admin
- Posts: 1346
- Joined: Tue May 03, 2016 8:51 pm
- Has thanked: 620 times
- Been thanked: 1322 times
- Contact:
Re: Additional buttons on GB0
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!
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!

- wermy
- Site Admin
- Posts: 1346
- Joined: Tue May 03, 2016 8:51 pm
- Has thanked: 620 times
- Been thanked: 1322 times
- Contact:
Re: Additional buttons on GB0
I go over that in the second part of the guide: http://sudomod.com/game-boy-zero-guide-part-2/LoafSlice wrote:@Wermy
Am I missing a thread for coding the pi and teensy?
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
wermy wrote:I go over that in the second part of the guide: http://sudomod.com/game-boy-zero-guide-part-2/LoafSlice wrote:@Wermy
Am I missing a thread for coding the pi and teensy?
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?
Who is online
Users browsing this forum: No registered users and 1 guest