PS2 mouse clicks

OK guys, I'm still pretty new with programming anything other than bash scripts so i've come up against something I can't figure out...

I've got the mouse X and Y displaying on a 4bit LCD just fine, and what appears to be a binary number being displayed in decimal, this number when I left click gets +1, right click +2 and of course both is +3, when the mouse if moved the number goes up, i assume this is related to the X and Y

The problem I have is going from that number to having a boolean variable per button.

The majority of my program is just the same as the one on the PS2 library page Arduino Playground - Ps2mouse just with it outputting to the LCD instead of serial

I've searched around, but I'm guessing I'm not looking for the right things as I'm sure the info must be around somewhere
And help, pointers etc. would be great :slight_smile:

Just make a variable mousebool, declare it as boolean and when the read from the PS2 = what you want on set it on and off set it off. Display mousebool on the screen and/or use it to manipulate what you want.

Hi,
It's pretty simple. The last three bits of that binary number correspond to the left, right and middle buttons. All you have to do is test the bit and you can have a variable for the button press.

Something like this:
LeftButton = DATA & 0x01;
RightButton = DATA & 0x02;
MiddleButton = DATA & 0x04;

Each one will have a 0 if button is not pressed and some positive value if it is pressed.

This web page explains what all the bits are for:
http://www.computer-engineering.org/ps2mouse/

Have fun,