Improved Teensy Program

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
cpaulik
Posts: 4
Joined: Sat May 14, 2016 2:29 am

Improved Teensy Program

Post by cpaulik » Mon May 16, 2016 6:05 am

I ran into problems when trying to configure things outside of Emulationstation e.g. emulator settings or running the emulationstation setup script. So I modified the teensy to send Arrow keys, RET, Backspace and ESC for some keys so that I can use the controls directly for simple config changes.

Code: Select all

#include <Bounce.h>

#define NUM_KEYS 12

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

Key keys[NUM_KEYS];

Key key(unsigned long 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_UP_ARROW, 0);
  keys[1] = key(KEY_DOWN_ARROW, 1);
  keys[2] = key(KEY_LEFT_ARROW, 2);
  keys[3] = key(KEY_RIGHT_ARROW, 3);
  keys[4] = key(KEY_ENTER, 4);
  keys[5] = key(KEY_BACKSPACE, 5);
  keys[6] = key('o', 6);
  keys[7] = key('k', 7);
  keys[8] = key(KEY_ESC, 8);
  keys[9] = key('z', 9);
  keys[10] = key('q',10);
  keys[11] = key('e',11);
}

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);
    }
  }
}
A = RET
B = Backspace
Select = ESC

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest