GBZ w/ BlackberryTrackball --> ScummVM

Show off your completed Game Boy Zero, or post your build logs here!
Post Reply
dezent
Posts: 15
Joined: Tue Aug 30, 2016 6:10 pm
Been thanked: 12 times

GBZ w/ BlackberryTrackball --> ScummVM

Post by dezent » 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.

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);
  }
   
 
}
Attachments
2016-10-30 21.57.21.jpg
2016-10-30 21.57.21.jpg (3.83 MiB) Viewed 9408 times

User avatar
ABH
Posts: 188
Joined: Sat May 28, 2016 7:01 pm
Location: Qatar
Has thanked: 82 times
Been thanked: 113 times

Re: GBZ w/ BlackberryTrackball --> ScummVM

Post by ABH » Sun Oct 30, 2016 3:48 pm

That's awesome , Thanks for shearing :)

Jace055
Posts: 32
Joined: Tue Sep 27, 2016 10:01 pm
Has thanked: 2 times
Been thanked: 12 times

Re: GBZ w/ BlackberryTrackball --> ScummVM

Post by Jace055 » Sun Oct 30, 2016 7:17 pm

This is a very cool idea. Do you have any other information? Which trackball did you use? There are dozens of different parts on eBay and it seems some of them are just the ball and not the encoder. How did you wire it?

dezent
Posts: 15
Joined: Tue Aug 30, 2016 6:10 pm
Been thanked: 12 times

Re: GBZ w/ BlackberryTrackball --> ScummVM

Post by dezent » Mon Oct 31, 2016 12:46 am

I have used this one.


ICSH044A icstation Blackberry Trackball Breakout Board
http://s.aliexpress.com/yuyIriuy

Power comes from teensyLC Pin 17 (the one on the oposite side of USB Port) ground is also connected to teensy.

Mouse directions are connected to Pin 15,16,18,19.
Left
Mouse Click is Pin 13

Pins 20,21,22,23 are used for the Trackball LEDs

They glow for around 1 second after Last Input.
Attachments
244416713-1510667243.jpg
244416713-1510667243.jpg (164.54 KiB) Viewed 9347 times

User avatar
Live2slay
Posts: 6
Joined: Sun Nov 13, 2016 3:53 pm
Has thanked: 1 time
Been thanked: 6 times

Re: GBZ w/ BlackberryTrackball --> ScummVM

Post by Live2slay » Tue Nov 15, 2016 6:55 pm

Nice! Really cool build.
Spartans never die, ..... unless 343 takes over the franchise :lol:

User avatar
Muon
Posts: 73
Joined: Thu Sep 22, 2016 2:35 am
Has thanked: 38 times
Been thanked: 5 times

Re: GBZ w/ BlackberryTrackball --> ScummVM

Post by Muon » Wed Nov 16, 2016 5:03 am

Genius! :D

User avatar
Billy Blaze
Posts: 78
Joined: Tue Sep 06, 2016 1:27 pm
Location: Gnosticus IV
Has thanked: 68 times
Been thanked: 33 times
Contact:

Re: GBZ w/ BlackberryTrackball --> ScummVM

Post by Billy Blaze » Thu Nov 24, 2016 3:26 pm

this is fantastic!

can you give us a video working example of how this looks in action please?! this'd be so helpful.
likewise I'd be thankful about a short review concerning the responsiveness and accuracy of this device. is it possible to navigate diagonal? and does your code provide an option of switching off the LEDs entirely?

I'm really curious about this idea. planing to implement a similar workaround myself. thought it'd be nice to have the trackball just on the backside of the GBZ to keep the front "clean".

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest