Shop OBEX P1 Docs P2 Docs Learn Events
Need help with simple programming question — Parallax Forums

Need help with simple programming question

AiR_GuNNeRAiR_GuNNeR Posts: 3
edited 2005-12-29 18:02 in BASIC Stamp
I want to activate one of three lights and monitor one of three switches based on a random number. The light part is easy. I have
Light1 var 0
Light2 var 1
Light3 var 2
LightThatIs on var WORD

I set LightThatIson to one of the lights, then call
HIGH LightThatIsOn
to activate thelight, and also use that variable to shut it off as well. The problem is I also need to monitor one of three switches depending on which light is on.

If i have this:
Switch1 PIN 4
Switch2 PIN 5
Switch3 PIN 6
ActiveSwitch var WORD

ActiveSwitch = Switch1

DO
LOOP WHILE ActiveSwitch = 0

ActiveSwitch isn't actually tied to Switch1, or Pin 4. Can you somehow declare a varable and set it to an input pin number programatically, or do you need to use the BUTTON statement?
Thanks in Advanced
Eric

Comments

  • metron9metron9 Posts: 1,100
    edited 2005-12-29 05:53
    activeswitch VAR Byte
    
    'Set activeswitch to one of the three below
    activeswitch= %01000000 'for pin 6
    activeswitch= %00100000 'for pin 5
    activeswitch= %00010000 'for pin 4
    
    
    ' INL is pins 0 through 7 as one Byte (SEE MEMORY AND VARIABLES IN HELP)
    ' so IF all pins are ON it will = 255 = (%11111111)
    ' The & (bitwise AND) operator masks only the PIN you set in activeswitch
    ' If the bit is not a 1, the return of the operation is zero
    DO
    LOOP WHILE (INL & activeswitch) = 0
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • AiR_GuNNeRAiR_GuNNeR Posts: 3
    edited 2005-12-29 18:02
    Thanks Kelvin!
    Regards,
    Eric
Sign In or Register to comment.