it is the same principle for optical mouse
the optical light led shines with a certain flash rate used as a locking feature and 512 level depth in expensive pens tablets etc
just taking place of the led side of the optical coupler
a simple 3 btn mouse {normal one microsoft protocal}
uses two optical switch
an optical mouse has one {or more} light source for all pickups
similar rule of one one zero zero direction control just scalled as locked level scaller achived
described above
i made pic code reads a mouse position as two signed bytes -128 - +128 ans -128 - +128 for up dn left right
so... easy stuff
fifteen lines of picbasic code
on a 20 charicter 2 line lcd
didnt ever finish it off for the project i was using it for
but it works as described
same code as a terminal reader but instead of display ascii too lcd just too display the decoded packet bytes
a mouse protocol for 3 btn
uses a 5 bytes packet
each byte has 8 bits as said above
the first byte stores the button data the the movement for x,y
the next byte updated data since last packet sent
and so on for 5 byte long packet
first three bits are the buttons left middle
http://www.mousetrak.com/3byte.htm
http://www.mousetrak.com/5byte.htm
attached is a design in proteus
for reading a mouse
the code isnt included as i cant find it
one is for simulations
the other is the power circuit for a mouse using a max232 too provide the mouse with energy so isnt intended too simulate
*** updated versions
i found an error in the connections too the pim
but youll get the idea
very so simple
each start bit
@9600bps
till stop bit