Shop OBEX P1 Docs P2 Docs Learn Events
BS1 - Assigning a value to a variable based upon multiple pin states — Parallax Forums

BS1 - Assigning a value to a variable based upon multiple pin states

KatyBriKatyBri Posts: 171
edited 2012-04-24 13:24 in BASIC Stamp
Hello Everyone. I've backed up to using a BS1 for a project, and has been years since I've used one. I have my code about finished, but need advise on a simple way to monitor the state of 4 input pins (P4,P5,P6,P7) which will be either HIGH or LOW and assign a value to a variable called DELAY based upon the pins states or combination of states.

BS1, PBasic 1.0

I need to not only check the state of each pin, but several combinations as follows:

P4,P5,P6,P7 normally LOW

P4 HIGH assign number 1 to DELAY
P5 HIGH assign number 2 to DELAY
P6 HIGH assign number 3 to DELAY
P7 HIGH assign number 4 to DELAY

P4 & P5 HIGH assign number 5 to DELAY
P4 & P6 HIGH assign number 6 to DELAY
P4 & P7 HIGH assign number 7 to DELAY

Suggestions on an easy way to do this would be appreciated. Thanks.

Comments

  • ercoerco Posts: 20,256
    edited 2012-04-24 13:24
    something as simple as...

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    SYMBOL delay = B0
    main:
    
    IF PIN4=0 THEN test5
    delay=1                  ' only if pin4 high
    test5: IF PIN5=0 THEN test6
    delay=2                   'only pin 5 high
    IF PIN4=0 THEN test6
    delay=5                   'pins 4&5 high
    test6:IF PIN6=0 THEN test7
    ....etc
    test7:....
    ....etc
    GOTO main
    

    now you can finish it
Sign In or Register to comment.