GBZ w/ BlackberryTrackball --> ScummVM
Posted: Sun Oct 30, 2016 3:11 pm
Hi everyone
using the D-pad in ScummVM is just pain, that was the reason for implementing a blackberry trackball (~5€@ebay as breakout).
The device itselfe works fine just a bit "unsmooth", but much better than D-pad controlls.
Teensy Code with "up, down esc, enter" for easier retropie menu navigation and mouse control.
Moving the trackball turns on the LED light (RGB+white).
The code is still beta, but works perfectly fine for me. A mixure of wermys code and tennsy example.
using the D-pad in ScummVM is just pain, that was the reason for implementing a blackberry trackball (~5€@ebay as breakout).
The device itselfe works fine just a bit "unsmooth", but much better than D-pad controlls.
Teensy Code with "up, down esc, enter" for easier retropie menu navigation and mouse control.
Moving the trackball turns on the LED light (RGB+white).
The code is still beta, but works perfectly fine for me. A mixure of wermys code and tennsy example.
Code: Select all
#include <Bounce.h>
#define NUM_KEYS 12
const int moveDistance = 15; // how much to move the mouse on each button press
const int redPin = 23;
const int bluePin = 22;
const int greenPin = 21;
const int whitePin = 20;
int j = 1;
float k = 0;
struct Key {
int keycode;
Bounce* bounce;
};
// 2 mouseknöpfe clicks
Bounce mbuttonl = Bounce(13, 10); // pin 13 click
Bounce mbuttonr = Bounce(14, 10); // pin 14 right click (not used yet)
// 4 richtungen
Bounce mup = Bounce(19, 10); // UP
Bounce mdown = Bounce(16, 10); // DOWN
Bounce mleft = Bounce(15, 10); // LEFT
Bounce mright = Bounce(18, 10); // RIGHT
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('z', 4);
keys[5] = key('x', 5);
keys[6] = key(KEY_ESC, 6);
keys[7] = key(KEY_RETURN, 7);
keys[8] = key(KEY_F5, 8);
keys[9] = key('o', 9);
keys[10] = key('q',10);
keys[11] = key('e',11);
}
void setup() {
setupKeys();
// maus setup
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(whitePin, OUTPUT);
//Mouse.screenSize(1920, 1080);
Mouse.screenSize(320, 240);
Keyboard.begin();
// pinMode(0, INPUT_PULLUP);
}
void loop() {
j = j + 1;
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);
}
}
// mouse
// LED wieder ausschlaten
k = j % 30000;
if (k == 0 ){
j = 1;
digitalWrite(whitePin, LOW);
digitalWrite(bluePin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(redPin, LOW);
}
mup.update();
mdown.update();
mleft.update();
mright.update();
mbuttonl.update();
mbuttonr.update();
//digitalWrite(whitePin, LOW);
//digitalWrite(bluePin, LOW);
//digitalWrite(redPin, LOW);
//digitalWrite(greenPin, LOW);
if (mleft.fallingEdge()) {
Mouse.move(-moveDistance, 0); // move Left
digitalWrite(redPin, HIGH);
}
if (mright.fallingEdge()) {
Mouse.move(moveDistance, 0); // move Right
digitalWrite(greenPin, HIGH);
}
if (mup.fallingEdge()) {
Mouse.move(0, -moveDistance); // move Up
digitalWrite(bluePin, HIGH);
}
if (mdown.fallingEdge()) {
Mouse.move(0, moveDistance); // move Down
digitalWrite(whitePin, HIGH);
}
// For the mouse buttons, we must detect both the falling and rising edges,
// to press the mouse button when the button on our digital pin is pressed,
// and to later release it when the physical button releases (the pin rises
// from low back to high, thanks to INPUT_PULLUP).
if (mbuttonl.fallingEdge()) {
Mouse.press(MOUSE_LEFT);
}
if (mbuttonl.risingEdge()) {
Mouse.release(MOUSE_LEFT);
}
if (mbuttonr.fallingEdge()) {
Mouse.press(MOUSE_RIGHT);
}
if (mbuttonr.risingEdge()) {
Mouse.release(MOUSE_RIGHT);
}
}