Help a noob with code for Teensy sketch?

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
User avatar
BlastoSupreme
Posts: 19
Joined: Mon Mar 26, 2018 1:29 pm
Has thanked: 6 times
Been thanked: 6 times

Help a noob with code for Teensy sketch?

Post by BlastoSupreme » Thu May 03, 2018 9:03 pm

Hello everyone,

I recently picked up Erik_Gee's common ground board (its great by the way :D ) and it has more buttons than the ABXY that is in Wermy's Teensy sketch in the written guide. I have no experience with programming at all. I tried to change it to add C, Z, F4 (for the function button), and the arrow keys for the D pad. I also wanted it to be in the same order on the board so I could use a ribbon cable and have it be flat. When I click the verify button it comes up with several problems at the bottom of the screen. I pasted those below.

Code: Select all

Game_Boy_Zero: In function 'void setupKeys()':
Game_Boy_Zero:22: warning: large integer implicitly truncated to unsigned type 
   keys[0] = key(KEY_F4, 0);
                          ^
Game_Boy_Zero:25: warning: large integer implicitly truncated to unsigned type 
   keys[3] = key(KEY_LEFT_ARROW, 3);
                                  ^
Game_Boy_Zero:26: warning: large integer implicitly truncated to unsigned type 
   keys[4] = key(KEY_UP_ARROW, 4);
                                ^
Game_Boy_Zero:27: warning: large integer implicitly truncated to unsigned type 
   keys[5] = key(KEY_DOWN_ARROW, 5);
                                  ^
Game_Boy_Zero:28: warning: large integer implicitly truncated to unsigned type 
   keys[6] = key(KEY_RIGHT_ARROW, 6);
                                   ^
Game_Boy_Zero:30: warning: large integer implicitly truncated to unsigned type 
   keys[8] = key(KEY_ENTER, 8);
                             ^
Sketch uses 9236 bytes (14%) of program storage space. Maximum is 63488 bytes.
Global variables use 3704 bytes (45%) of dynamic memory, leaving 4488 bytes for local variables. Maximum is 8192 bytes. 
Here is the sketch I edited.

Code: Select all

#include <Bounce.h>

#define NUM_KEYS 15

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(KEY_F4, 0);
  keys[1] = key('r', 1);
  keys[2] = key('l', 2);
  keys[3] = key(KEY_LEFT_ARROW, 3);
  keys[4] = key(KEY_UP_ARROW, 4);
  keys[5] = key(KEY_DOWN_ARROW, 5);
  keys[6] = key(KEY_RIGHT_ARROW, 6);
  keys[7] = key('s', 7);
  keys[8] = key(KEY_ENTER, 8);
  keys[9] = key('z', 9);
  keys[10] = key('c', 10);
  keys[11] = key('x', 11);
  keys[12] = key('y', 12);
  keys[13] = key('b', 13);
  keys[14] = key('a', 14);
}

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);
    }
  }
}
I would greatly appreciate any help you could provide. ^_^

User avatar
erik_gee
Posts: 356
Joined: Thu Jun 16, 2016 12:57 am
Location: United States
Has thanked: 137 times
Been thanked: 193 times

Re: Help a noob with code for Teensy sketch?

Post by erik_gee » Sun May 06, 2018 2:23 pm

What happens when you actually upload it to the board? Warnings won't prevent you from uploading, only an error will.

I usually see that warning when you try to pass a larger bit value into a smallee one. Such as passing a 16bit integer into and 8bit variable. It's just warning that it's cutting off the extra bits.

Try uploading the board and post back with what it's doing
GBC AIO kit Sales Thread:https://www.sudomod.com/forum/viewtopic.php?f=38&t=9928

Bunch of different shoulder button kits Sales Thread:viewtopic.php?f=38&t=6233&p=63192#p63192

AIO board for DMG Sales Thread:
viewtopic.php?f=38&t=6431

6 Button Common Ground Board Sales Thread: viewtopic.php?f=38&t=4811

GunZi
Posts: 32
Joined: Sun May 06, 2018 4:50 pm
Has thanked: 2 times
Been thanked: 4 times

Re: Help a noob with code for Teensy sketch?

Post by GunZi » Sun May 06, 2018 4:57 pm

Change

Code: Select all

struct Key {
  char keycode;
  Bounce* bounce;
};
into this

Code: Select all

struct Key {
  unsigned long int keycode;
  Bounce* bounce;
};
and change this

Code: Select all

Key key(char keycode, int pin) {
into this

Code: Select all

Key key(unsigned long int keycode, int pin) {
This worked when I had the same problem as you :)

User avatar
erik_gee
Posts: 356
Joined: Thu Jun 16, 2016 12:57 am
Location: United States
Has thanked: 137 times
Been thanked: 193 times

Re: Help a noob with code for Teensy sketch?

Post by erik_gee » Sun May 06, 2018 8:03 pm

GunZi wrote:
Sun May 06, 2018 4:57 pm
Change

Code: Select all

struct Key {
  char keycode;
  Bounce* bounce;
};
into this

Code: Select all

struct Key {
  unsigned long int keycode;
  Bounce* bounce;
};
and change this

Code: Select all

Key key(char keycode, int pin) {
into this

Code: Select all

Key key(unsigned long int keycode, int pin) {
This worked when I had the same problem as you :)
Yup, that way it won't truncate the extra bits as they will be of the same size
GBC AIO kit Sales Thread:https://www.sudomod.com/forum/viewtopic.php?f=38&t=9928

Bunch of different shoulder button kits Sales Thread:viewtopic.php?f=38&t=6233&p=63192#p63192

AIO board for DMG Sales Thread:
viewtopic.php?f=38&t=6431

6 Button Common Ground Board Sales Thread: viewtopic.php?f=38&t=4811

User avatar
BlastoSupreme
Posts: 19
Joined: Mon Mar 26, 2018 1:29 pm
Has thanked: 6 times
Been thanked: 6 times

Re: Help a noob with code for Teensy sketch?

Post by BlastoSupreme » Sun May 06, 2018 9:01 pm

Hey,

So I loaded it into the teensy and the buttons came back like this:

Up: R
Right: O
Down: Q
Left: P
Select: s
Start: (
Z: z
C: c
Y: y
X: x
B: b
A: a
L: l
R: r
F4: =

Im going to add the suggested changes and see what happens.

User avatar
BlastoSupreme
Posts: 19
Joined: Mon Mar 26, 2018 1:29 pm
Has thanked: 6 times
Been thanked: 6 times

Re: Help a noob with code for Teensy sketch?

Post by BlastoSupreme » Sun May 06, 2018 9:08 pm

It worked!!! Yay! This is so exciting! Thank you both for your help!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest