[Coco] Wico Command Control Trackball on eBay

Barry Nelson barry.nelson at amobiledevice.com
Tue Oct 13 22:39:43 EDT 2015


I wrote this sketch, and checked that it compiled, but I have not built or tested the circuit yet. It "should" work. It will need a lowpass filter on the analog outputs with an inductor in series with the output and a capacitor to ground. Here is the Arduino sketch… (untested) It uses the ps2 mouse library at: http://playground.arduino.cc/ComponentLib/Ps2mouse
It emulates a simple CoCo low resolution mouse, it will NOT work with the hires interface. It might work with the new hires mouse software driver. It should work with any ps2 mouse or trackball.

#include <ps2.h>

/*
 * an Arduino sketch to interface a ps/2 mouse
 * to a Tandy Color Computer.
 * The Arduino should be able to get power from the joystick port
 */

/*
 * Pin 3 is the mouse data pin, pin 4 is the clock pin
 * Feel free to use whatever pins are convenient.
 */
PS2 mouse(3, 4);

#define CoCoXpin 5
#define CoCoYpin 6
#define CoCoButton1 7
#define CoCoButton2 8

/*
 * initialize the mouse. Reset it, and place it into remote
 * mode, so we can get the encoder data on demand.
 */
void mouse_init()
{
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
}

void setup()
{
  pinMode(CoCoXpin, OUTPUT);
  pinMode(CoCoYpin, OUTPUT);
  pinMode(CoCoButton1, OUTPUT);
  pinMode(CoCoButton2, OUTPUT);
  mouse_init();
  analogWrite(CoCoXpin,128); // start with CoCo x centered
  analogWrite(CoCoYpin,128); // start with CoCo y centered
  digitalWrite(CoCoButton1,HIGH); // start with CoCo button 1 not pressed
  digitalWrite(CoCoButton2,HIGH); // start with CoCo button 2 not pressed
}

/*
 * get a reading from the mouse and report it back to the
 * host via the serial line.
 */
void loop()
{
  char mstat;
  char mx;
  char my;
  int cocoxv=128; // start with CoCo x centered
  int cocoyv=128; // start with CoCo y centered

  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();
  if (mstat & 16) { // bit 4 of mstat is x direction
    mx = -mx;
  }
  // mx = -mx; // reverse if needed
  if (mstat & 32) { // bit 5 of mstat is y direction
    my = -my;
  }
  // my = -my; // reverse if needed
  cocoxv += mx; // add mouse movement to CoCo x position
  if (cocoxv > 255) { // limit to 0 - 255 for 0 - 5 volts
    cocoxv=255;
  }
  if (cocoxv < 0) {
    cocoxv=0;
  }
  cocoyv += my; // add mouse movement to CoCo y position
  if (cocoyv > 255) { // limit to 0 - 255 for 0 - 5 volts
    cocoyv=255;
  }
  if (cocoyv < 0) {
    cocoyv=0;
  }
  analogWrite(CoCoXpin,cocoxv); // Set CoCo x value
  analogWrite(CoCoYpin,cocoyv); // Set CoCo y value
  if (mstat & 1) { // Mouse left button pressed?
    digitalWrite(CoCoButton1,LOW); // Press CoCo button 1
  } else {
    digitalWrite(CoCoButton1,HIGH);
  }
  if (mstat & 2) { // Mouse right button pressed?
    digitalWrite(CoCoButton2,LOW); // Press CoCo button 2
  } else {
    digitalWrite(CoCoButton2,HIGH);
  }
  // mstat & 4 or bit 2 is the mouse middle button
  // mstat & 8 or bit 3 is always on
  // mstat & 64 or bit 6 is X overflow
  // mstat & 128 or bit 7 is Y overflow
}


More information about the Coco mailing list