Shop OBEX P1 Docs P2 Docs Learn Events
need help with simple case statement — Parallax Forums

need help with simple case statement

laser-vectorlaser-vector Posts: 118
edited 2010-09-22 23:11 in Propeller 1
hi all

im trying to sample from an analog joystick, in this case im setting up a deadzone with a case statement

RCValue is the variable from the joystick axis (between 0 - 4880)
CON
  deadzone = 100
  joy1y    = 4880

CASE RCValue       
       ((joy1y/2)-deadzone)..((joy1y/2)+deadzone)     : outa[2]~~
       RCValue > ((joy1y/2)+deadzone)                     : outa[2]~
       RCValue < ((joy1y/2)-deadzone)                     : outa[2]~

the first part of the case statement works perfectly, however the parts where RCValue is compared to be either grater than or less than is not working.

how is this done?

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-09-22 17:08
    See page 59 - 61 of the propeller manual for a description of the case statement.

    You need to remove "RCValue" from the last 2 lines for them to be correct.
  • AribaAriba Posts: 2,690
    edited 2010-09-22 23:11
    Something like:
    CASE RCValue       
       0..joy1y/2-deadzone                 : outa[2]~
       joy1y/2-deadzone..joy1y/2+deadzone  : outa[2]~~
       joy1y/2+deadzone..joy1y             : outa[2]~
    

    but I would do it with if..else:
    if RCValue < joy1y/2-deadzone
         outa[2]~
      elseif RCValue > joy1y/2+deadzone
         outa[2]~
      else
         outa[2]~~
    

    Andy
Sign In or Register to comment.