Test Parallax Mouse Puzzle
coryco2
Posts: 107
I attempted to add a few lines of code to the "Test Parallax Mouse" demo code in order to return the scroll wheel value to zero whenever the wheel's direction of movement changed by more than one click, but oddly the code seemed to slow way down, and only work (sorta of) coming from a negative to positive scroll value; the scroll value would not exceed 1 on the positive side.
Can anyone see why this code is behaving in this way?
Can anyone see why this code is behaving in this way?
'' Test Parallax Mouse.spin '' Displays Parallax mouse X, Y, and Scroll button coordinates along with the scroll wheel, '' right and left button states in the Parallax Serial Terminal. '' See 28060-PS2Adapter.pdf for schematics and instructions. CON _clkmode = xtal1 + pll16x ' System clock settings _xinfreq = 5_000_000 HOME = 1 ' Parallax Serial Terminal constants CRSRXY = 2 CR = 13 CLREOL = 11 CLS = 16 OBJ mouse : "Mouse" ' Declare Mouse object debug : "FullDuplexSerial" ' Declare FullDuplexSerial object PUB MouseDisplay | mousex, mousey, mousez, mousebtns, mousezwheel, mousezwheelprevious mouse.start(24, 25) ' Start mouse debug.start(31, 30, 0, 57600) ' Start serial connection waitcnt(clkfreq + cnt) ' Wait 1 s before starting ' Display static text. debug.str(String(CLS, "Mouse", CR, "x = ", CR, "y = ", CR, "scroll = ", CR, "CRL", HOME)) repeat mousex := mouse.delta_x ' Get mouse data mousey := mouse.delta_y mousez := mouse.delta_z mousebtns := mouse.buttons mousezwheel:= mousezwheel + mousez IF (mousezwheelprevious>0) AND (mousez <-1) 'Set mousezwheel to zero if scroll changes direction by more than 1 mousezwheel:=0 IF (mousezwheelprevious<0) AND (mousez >1 ) mousezwheel:=0 mousezwheelprevious:= mousezwheel debug.str(string(CRSRXY, 4, 1)) ' Display mouse data debug.dec(mousex) debug.str(string(CLREOL, CRSRXY, 4, 2)) debug.dec(mousey) debug.str(string(CLREOL, CRSRXY, 9, 3)) debug.dec(mousez) debug.str(string(CLREOL, CRSRXY, 14, 3)) debug.dec(mousezwheel) debug.str(string(CLREOL, CR, CR)) debug.bin(mouse.buttons, 5)
Comments