Additional buttons on GB0

General GBZ-related chat goes here. Share ideas, tips and tricks, or ask questions that don't fit into the hardware/software help forums.
Post Reply
Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Additional buttons on GB0

Post by Jimanez11 » Fri May 27, 2016 12:32 pm

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.

User avatar
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

Post by wermy » Fri May 27, 2016 12:44 pm

Can you post what your teensy code looks like now?
ImageImageImageImage

Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Re: Additional buttons on GB0

Post by Jimanez11 » Fri May 27, 2016 12:54 pm

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);
}
}
}

User avatar
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

Post by wermy » Fri May 27, 2016 1:12 pm

Looks like it should work. :\ Dumb question but you do have the new buttons connected to the same ground as the other ones, right?
ImageImageImageImage

User avatar
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

Post by wermy » Fri May 27, 2016 1:14 pm

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! :)
ImageImageImageImage

Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Re: Additional buttons on GB0

Post by Jimanez11 » Fri May 27, 2016 2:20 pm

Worked like a charm!!! Thanks! :D

User avatar
LoafSlice
Posts: 67
Joined: Mon May 16, 2016 2:58 pm
Has thanked: 9 times
Been thanked: 3 times

Re: Additional buttons on GB0

Post by LoafSlice » Fri May 27, 2016 3:21 pm

@Wermy

Am I missing a thread for coding the pi and teensy?

User avatar
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

Post by wermy » Fri May 27, 2016 4:36 pm

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.
ImageImageImageImage

User avatar
LoafSlice
Posts: 67
Joined: Mon May 16, 2016 2:58 pm
Has thanked: 9 times
Been thanked: 3 times

Re: Additional buttons on GB0

Post by LoafSlice » Fri May 27, 2016 5:57 pm

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest