Shop OBEX P1 Docs P2 Docs Learn Events
CASE usage — Parallax Forums

CASE usage

El PaisaEl Paisa Posts: 375
edited 2006-08-18 19:47 in Propeller 1
I quite understand the manual entry about CASE.
I wonder if somebody give me a couple of examples of the use of CASE.
I really appeciate.

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2006-08-18 19:46
    case kb.getkey
          $C0: on_time := on_time - 10 #>14        ' Left arrow (limited to 14 clock cycles min)
          $C1: on_time := on_time + 10             ' Right arrow
          $C2: off_time := off_time + 10           ' Up arrow
          $C3: off_time := off_time - 10 #>57      ' Down arrow (limited to 57 clock cycles min)
    



    This is from the object that produces pulses that I posted:

    http://forums.parallax.com/forums/default.aspx?f=25&m=139628

    it gets the code for the key pressed using the getkey method and compares it to $C0 to $C3 in turn. If for example the key was the right arrow, kb.getkey would be $C1 and the code "on_time := on_time + 10 " would be run.

    Once one of the cases is found to be true no others are checked and it jumps to the next part of the program.

    Graham
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2006-08-18 19:47
    p.s. The #> makes sure that on_time can be no smaller than 14 and the #>57 makes sure the off time can be no smaller than 57.
Sign In or Register to comment.