Shop OBEX P1 Docs P2 Docs Learn Events
case — Parallax Forums

case

mikeamikea Posts: 283
edited 2012-08-04 10:57 in Propeller 1
I'm having a problem getting "case" to work in this code. i can see in the pst that it is seeing the pulses accurately. The compiler highlights the"<" just below the case and expects an expression term. I've tried this different ways with no luck. What am i doing wrong? -mike
  repeat
     waitpeq(%000, |< 2, 0) ' wait for Pin 2 to go low         '
     waitpeq(%100, |< 2, 0) 'Wait for Pin 2 to go high         '
     startpulsep:=cnt                                          '
     waitpeq(%000, |< 2, 0) ' wait for Pin 2 to go low         '
     endpulsep:=cnt                                            '    read  pulse width  from receiver
     waitpeq(%100, |< 2, 0) 'Wait for Pin 2 to go high         '
                                             '
     pulsewidthp:=endpulsep-startpulsep

     case pulsewidthp                  'test current pulsewidth value against the values below it
       <120000 and  <128000 : dead    'go to the dead method 
       >128000 :down                 'go to the down method
       <120000 :up                  'go to the up method

Comments

  • cavelambcavelamb Posts: 720
    edited 2012-08-04 10:03
    case X+Y 'Test X+Y
        10, 15: !outa[0] 'X+Y = 10 or 15? Toggle P0
        20..30: !outa[2] 'X+Y in 20 to 30? Toggle P2
    

    Page 60, 61 of the manual.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-04 10:04
    That's not the proper syntax. Reread the Propeller Manual section on the CASE statement. For what you want, you'll need to use IF statements like:
    IF pulsewidthp < 120000
       up
    ELSEIF pulsewidthp > 128000
       down
    ELSE
       dead
    
  • mikeamikea Posts: 283
    edited 2012-08-04 10:23
    I see it now in the manual, if then else for comparing a number of different values. Thanks guys. -mike
  • cavelambcavelamb Posts: 720
    edited 2012-08-04 10:57
    or 0 .. 12000 for the case structure
Sign In or Register to comment.