hello everyone,
i am doing a project on interfacing of ps2 mouse with arduino.
i want to take reading of x and y coordinate. i used these codes Arduino Playground - Ps2mouse .
but my problem is:
as soon as mouse stops x and y reading resets to 0,0.
its maximum count is 127 in both x and y directions.
Hey navneet123,
as far as I can see, your second problem is caused by the data type the x- and y-positions are stored in. They're stored in variables of char-type. This type holds 8 bit, which gives you a range of 0 to 28-1=255. If you also assume negative x- and y-movement you get a maximum of 127 in each direction.
On one hand the reset is caused by the mouse.read()-command, which returns the absolute mouse movement inbetween the period of time in which the clk-signal is on high-level. The x- and y-positions are then set to this absolute amount. That would not be a problem if you moved your mouse only once. So, the second cause ist the actual setting of the x- and y-positions als shown below:
mx = mouse.read();
my = mouse.read();
You see, you always get the x- and y-movement from within the last clk-high-level. If you change the code to
mx = mx + mouse.read();
my = my + mouse.read();
you would get a position relative to the point at when you first startet the programm/your Arduino. But keep in mind, that the char-type limits your overall movment area to a field of 256 x 256. So if you want a bigger area you should change the type to int. That would give you 16bit to store movement in.