Hi everyone,
i'm trying to control the direction of a servo motor using the 2 buttons of a PS/2 Mouse. What I want is too simple: when the left button is pressed, the position of servo goes to one side, and when the right button is pressed, the position of servo goes to the other side.
I'm trying to use this library: Arduino Playground - Ps2mouse
the first one from the topic (ps2.zip).
The code i wrote is:
#include <ps2.h>
#include <Servo.h>
PS2 mouse(6, 5);
Servo myservo;
char mstat;
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()
{
Serial.begin(9600);
mouse_init();
myservo.attach(10);
}
void loop()
{
mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
Serial.println(mstat, BIN);
if (mstat == 1001, BIN){
myservo.write(180);
}
if (mstat == 1010, BIN){
myservo.write(0);
}
}
I used the values 1001 and 1010 for mstat because i saw that values in the monitor serial, when i press the buttons.
But, it doesn't works!
Can you help me?