Teensy key wasd configuration - why?

General GBZ-related chat goes here. Share ideas, tips and tricks, or ask questions that don't fit into the hardware/software help forums.
User avatar
alien0matic
Posts: 102
Joined: Wed Jun 08, 2016 7:20 am
Has thanked: 15 times
Been thanked: 23 times

Re: Teensy key wasd configuration - why?

Post by alien0matic » Fri Jul 29, 2016 12:22 am

I replaced the keys with arrow keys, enter, tab, etc. It works like a charm and you can quit and use menus that take you to the console.
You should really look which key is soldered to what pin, otherwise it is REALLY confusing to use ;)
Oh and I added another tactile button to act as an ESC key.

Code: Select all

#include <Bounce.h>

#define NUM_KEYS 13

struct Key {
  int keycode;
  Bounce* bounce;
};

Key keys[NUM_KEYS];

Key key(int 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_LEFT_ARROW, 0);
  keys[1] = key(KEY_UP_ARROW, 1);
  keys[2] = key(KEY_DOWN_ARROW, 2);
  keys[3] = key(KEY_RIGHT_ARROW, 3);
  keys[4] = key(KEY_TAB, 4);
  keys[5] = key(KEY_RETURN, 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(KEY_ESC, 12);
}

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

User avatar
skrapps914
Posts: 184
Joined: Sat May 28, 2016 8:14 pm
Has thanked: 63 times
Been thanked: 33 times

Re: Teensy key wasd configuration - why?

Post by skrapps914 » Fri Jul 29, 2016 12:33 am

thanks for your help @fleder really appreciate it. i'm going to try the hex's tomorrow morning. if that doesnt work, ill try the decimals.

User avatar
skrapps914
Posts: 184
Joined: Sat May 28, 2016 8:14 pm
Has thanked: 63 times
Been thanked: 33 times

Re: Teensy key wasd configuration - why?

Post by skrapps914 » Fri Jul 29, 2016 12:37 am

alien0matic wrote:I replaced the keys with arrow keys, enter, tab, etc. It works like a charm and you can quit and use menus that take you to the console.
You should really look which key is soldered to what pin, otherwise it is REALLY confusing to use ;)
Oh and I added another tactile button to act as an ESC key.

Code: Select all

#include <Bounce.h>

#define NUM_KEYS 13

struct Key {
  int keycode;
  Bounce* bounce;
};

Key keys[NUM_KEYS];

Key key(int 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_LEFT_ARROW, 0);
  keys[1] = key(KEY_UP_ARROW, 1);
  keys[2] = key(KEY_DOWN_ARROW, 2);
  keys[3] = key(KEY_RIGHT_ARROW, 3);
  keys[4] = key(KEY_TAB, 4);
  keys[5] = key(KEY_RETURN, 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(KEY_ESC, 12);
}

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

thanks @alien0matic i will give this a shot and see how i like it.

George.p
Posts: 14
Joined: Thu Jan 25, 2018 11:04 pm

Re: Teensy key wasd configuration - why?

Post by George.p » Mon Oct 01, 2018 3:56 am

Anyone knows how to add an analog psp joystick to this script? And where to solder the wieres on the teensy board? Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest