dumped all my old arduino stuff in here.
This commit is contained in:
parent
8cc6f23f59
commit
8f8959b76f
76 changed files with 8127 additions and 2 deletions
52
ps2_mouse/ps2_mouse.pde
Normal file
52
ps2_mouse/ps2_mouse.pde
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#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(6, 5);
|
||||
|
||||
/*
|
||||
* initialize the mouse. Reset it, and place it into remote
|
||||
* mode, so we can get the encoder data on demand.
|
||||
*/
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
mouse.init_mouse();
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
Serial.print(mstat, BIN);
|
||||
Serial.print("\tX=");
|
||||
Serial.print(mx, DEC);
|
||||
Serial.print("\tY=");
|
||||
Serial.print(my, DEC);
|
||||
Serial.println();
|
||||
delay(20); /* twiddle */
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue