#include <ps2.h>/* * an arduino sketch to interface with a ps/2 mouse. * Also uses serial protocol to talk back to the host * and report what it finds. *//* * Pin 5 is the mouse data pin, pin 6 is the clock pin * Feel free to use whatever pins are convenient. */PS2 mouse(10, 6);/* * 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(){ Serial1.begin(250000); Serial1.println("Setting up the mouse"); mouse_init(); Serial1.println("Starting...");}/* * 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; /* 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(); /* send the data back up */ Serial1.print(mstat, BIN); Serial1.print("\tX="); Serial1.print(mx, DEC); Serial1.print("\tY="); Serial1.print(my, DEC); Serial1.println(); delay(1000); /* twiddle */}
Well, turns out i had to disable the serial shell...Sadly, i didnt find any information about setting the port to the correct mode, so i will post instructions on how i did it...