Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2015 11:23
Show Gist options
  • Save anonymous/b2989fb2fc50c5eb5005 to your computer and use it in GitHub Desktop.
Save anonymous/b2989fb2fc50c5eb5005 to your computer and use it in GitHub Desktop.
#include <ps2.h>
PS2 mouse(6, 5);
bool left, right;
void mouse_init()
{
mouse.write(0xff);
mouse.read();
mouse.read();
mouse.read();
mouse.write(0xf0);
mouse.read();
delayMicroseconds(100);
}
void setup()
{
Serial.begin(9600);
mouse_init();
Mouse.begin();
}
void loop()
{
char mstat;
char mx;
char my;
mouse.write(0xeb);
mouse.read();
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
bool l = mstat & 1, r = mstat & 2;
if (l != left){
left = l;
if (l) Mouse.press();
else Mouse.release();
}
if (r != right){
right = r;
if (r) Mouse.press(MOUSE_RIGHT);
else Mouse.release(MOUSE_RIGHT);
}
if (mx || my) Mouse.move(mx, -my, 0);
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment