Shop OBEX P1 Docs P2 Docs Learn Events
Test Parallax Mouse Puzzle — Parallax Forums

Test Parallax Mouse Puzzle

coryco2coryco2 Posts: 107
edited 2013-11-14 20:04 in Propeller 1
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?
'' 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

  • kuronekokuroneko Posts: 3,623
    edited 2013-11-14 19:14
    Not sure if it solves your problem (no scroll wheel mouse available for testing) but you should put a space in front of the -1 (currently it reads mousez <-1) otherwise it's interpreted as rotate left.
  • coryco2coryco2 Posts: 107
    edited 2013-11-14 19:35
    Good eye! It solves part of it; now the scroll values will go into positive values. But the code is still displaying values on the terminal very slowly, and not resetting mousezwheel to zero on a change of direction of more than one scroll wheel tick in the opposite direction.
  • kuronekokuroneko Posts: 3,623
    edited 2013-11-14 20:04
    coryco2 wrote: »
    ... and not resetting mousezwheel to zero on a change of direction of more than one scroll wheel tick in the opposite direction.
    Works fine here. You just have to make sure that your z changes are big enough, e.g. if I move the wheel slowly (found one) then all I get are +/- 1 changes, turning it faster gives me more and the value resets and continues from 0.
Sign In or Register to comment.