teensy 2.0 help

Arduino/Teensy software/code questions and discussion
Post Reply
kylewismith
Posts: 34
Joined: Tue Jun 28, 2016 12:44 pm
Has thanked: 5 times
Been thanked: 2 times

teensy 2.0 help

Post by kylewismith » Tue Jun 28, 2016 2:09 pm

hi i have a teensy 2.0 in my gbz. i have built it with 4 buttons on the back l1 l2 r1 r2 the arduino code in the guide works for everything but the back 4, any way i could make this work any help would be much appreciated

User avatar
wermy
Site Admin
Posts: 1340
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 609 times
Been thanked: 1317 times
Contact:

Re: teensy 2.0 help

Post by wermy » Tue Jun 28, 2016 6:09 pm

kylewismith wrote:hi i have a teensy 2.0 in my gbz. i have built it with 4 buttons on the back l1 l2 r1 r2 the arduino code in the guide works for everything but the back 4, any way i could make this work any help would be much appreciated
You should just need to add a couple more buttons in the setup method, and change the number of buttons at the top. Try this out:

Code: Select all

#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('a', 2);
  keys[3] = key('d', 3);
  keys[4] = key('p', 4);
  keys[5] = key('l', 5);
  keys[6] = key('o', 6);
  keys[7] = key('k', 7);
  keys[8] = key('x', 8);
  keys[9] = key('z', 9);
  keys[10] = key('q',10);
  keys[11] = key('e',11);
  keys[12] = key('r',12);
  keys[13] = key('t',13);
}

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

kylewismith
Posts: 34
Joined: Tue Jun 28, 2016 12:44 pm
Has thanked: 5 times
Been thanked: 2 times

Re: teensy 2.0 help

Post by kylewismith » Wed Jun 29, 2016 3:00 am

Brilliant that worked a treat thanks alot for you help. I also had the wires soldered at the wrong end ha

9volt
Posts: 22
Joined: Wed Apr 12, 2017 5:48 pm
Been thanked: 1 time

Re: teensy 2.0 help

Post by 9volt » Sat Apr 15, 2017 11:40 pm

I'm having some problems with the Teensy 2.0, also. It seems that the Teensy loader isn't connecting to the Teensy. The Program and Reboot buttons are gray. Also, IDE says the Teensy isn't responding to USB requests.

I'm using Arduino IDE 1.6.9 and TeensyLoader 1.36

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest