Hi,
i'm reading a mouse sensor on the serial monitor using this code , but i have to disconnect/connect the 5v pin of the sensor many times before i get the data from it going on the serial monitor, can someone please see if there is any error in the code
#include <ps2.h>
PS2 mouse(6, 5);
char mstat,mx,my;
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 mouse_pos(char &mstat, char &mx, char &my){
mouse.write(0xEB);
mouse.read();
mstat=mouse.read();
mx=mouse.read();
my=mouse.read();
}
void setup()
{
Serial.begin(115200);
mouse_init();
}
void loop()
{
mouse_pos(mstat,mx,my);
Serial.println(my,DEC);
}