Shop Learn
Using Case — Parallax Forums

Using Case

IguanamanIguanaman Posts: 27
edited 2022-05-14 07:12 in Propeller 1

Hello. In the Propeller Manual v1.0 page 171 Spin language reference - CASE. I made this program.

''''_clkmode = xtal1 + pll16x
''''_xinfreq = 5_000_000
''''X = 2
PUB start
''''case x
'''''''0: outa[0]:=1
''''''''''''waitcnt(clkfreq + cnt)
''''''1: outa[1]:= 1
'''''''''''waitcnt(clkfreq + cnt)
''''''2: outa[2]:=1
''''''''''waitcnt(clkfreq + cnt)
''''''3: outa[3]:=1
'''''''''''waitcnt(clkfreq + cnt)
This program will light a LED at the pin out listed to let me know what number X is. Can I use letters instead of numbers? Can this program be expanded to pick something typed in that closely resembles some encoded close to input? All the commands that the propeller knows I only know about 15 commands and I am trying to learn more. I love the IF...ELSEIF...ELSE commands. It is frustrating to know that my little brain will never be able to access the full capability's of the Propeller language. The possibility  are endless! Thank you for any information. 13 may 2022(fri)

ModEdit: Code tags added


  • Nice use of apostrophes to highlight your indenting! It's unnecessary, though. Precede and succeed your code with a line consisting of three backticks (```), and your indenting will display just as you've written it.


  • JonnyMacJonnyMac Posts: 8,053

    Can I use letters instead of numbers?

    Sure. You could take a key from the terminal and use it to control your LEDs like this:

        c := term.rx
        case c
          "a", "A" : io.toggle(LED_A)
          "b", "B" : io.toggle(LED_B)
          "c", "C" : io.toggle(LED_C)
          "d", "D" : io.toggle(LED_D)
          other    : clear_leds

    This will work with upper- and lowercase letters.

    You can make your program a bit easier to read by using a couple simple libraries. I've attached an archive to help yo get started.

Sign In or Register to comment.