TOGGLE flips the state of an output pin -- not what you're looking for.
You can create a mode variable in your program, then update it with a button input. I'm a bit fan of using the modulus operator in these cases. If you have four modes, it would be sensible to keep the value in the 0 - 3 range. You can do that with the mod opeator:
IF (NextBtn = 1) THEN mode = mode + 1 // 4
IF (PrevBtn = 1) THEN mode = mode + 3 // 4
The first line will go 0, 1, 2, 3, 0, 1 .... and so on. The second line will go 3, 2, 1, 0, 3, 2 .... and so on.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Jon Williams
Applications Engineer, Parallax
Dallas Office
Let me suggest, then, that you work through our "What's A Microcontroller?" book -- you can download it free and it will the few hours you spend with it will be well rewarded in time and frustration saved. StampWorks is also helpful and has lots of BS2 samples that you can plug into your application.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Jon Williams
Applications Engineer, Parallax
Dallas Office
Comments
You can create a mode variable in your program, then update it with a button input. I'm a bit fan of using the modulus operator in these cases. If you have four modes, it would be sensible to keep the value in the 0 - 3 range. You can do that with the mod opeator:
IF (NextBtn = 1) THEN mode = mode + 1 // 4
IF (PrevBtn = 1) THEN mode = mode + 3 // 4
The first line will go 0, 1, 2, 3, 0, 1 .... and so on. The second line will go 3, 2, 1, 0, 3, 2 .... and so on.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
VAR EYEOFF BYTE
VAR EYEON BYTE
VAR CEYEOFF BYTE
VAR CEYEON BYTE
DIRS=11001011 'Input/Output
PINS=10000011 'Low/High
SYMBOL Trigger=PIN0 'INPUT
SYMBOL Emitter=PIN1 'OUTPUT
SYMBOL Detector=PIN2 'INPUT
SYMBOL Solenoid=PIN3 'OUTPUT
SYMBOL Dwell=B4
SYMBOL Drop=B5
LET dwell=20 'ms
LET drop=20 'ms
ReadyLOOP:
BUTTON 0,1,255,0,B1,0,ReadyLOOP
HIGH 3 'Activates Solenoid
PAUSE Dwell
LOW 3 'Deactivates Solenoid
PAUSE Drop
GOTO ReadyLOOP
EYEOFF:
DIRS=11001011 'Input/Output
PINS=10000011 'Low/High
SYMBOL Trigger=PIN0 'INPUT
SYMBOL Emitter=PIN1 'OUTPUT
SYMBOL Detector=PIN2 'INPUT
SYMBOL Solenoid=PIN3 'OUTPUT
SYMBOL Dwell=B4
SYMBOL Drop=B5
LET dwell=20 'ms
LET drop=20 'ms
BUTTON 0,1,255,0,B1,0,ReadyLOOP
HIGH 3 'Activates Solenoid
PAUSE Dwell
LOW 3 'Deactivates Solenoid
PAUSE Drop
GOTO EYEOFF
END
EYEON:
IR_DETECT VAR BIT
LOW 7
PAUSE 50
FREQOUT 7, 1, 38500
IR_DETECT = IN8
IF IR_DETECT = 1 THEN BROKEN
BROKEN:
IF IR_DETECT = BROKEN THEN
DIRS=11001011 'Input/Output
PINS=10000011 'Low/High
SYMBOL Trigger=PIN0 'INPUT
SYMBOL Emitter=PIN1 'OUTPUT
SYMBOL Detector=PIN2 'INPUT
SYMBOL Solenoid=PIN3 'OUTPUT
SYMBOL Dwell=B4
SYMBOL Drop=B5
LET dwell=20 'ms
LET drop=20 'ms
BUTTON 0,1,255,0,B1,0,ReadyLOOP
HIGH 3 'Activates Solenoid
PAUSE Dwell
LOW 3 'Deactivates Solenoid
PAUSE Drop
GOTO EYEON
END
CEYEOFF:
DIRS=11001011 'Input/Output
PINS=10000011 'Low/High
SYMBOL Trigger=PIN0 'INPUT
SYMBOL Emitter=PIN1 'OUTPUT
SYMBOL Detector=PIN2 'INPUT
SYMBOL Solenoid=PIN3 'OUTPUT
SYMBOL Dwell=B4
SYMBOL Drop=B5
LET dwell=20 'ms
LET drop=20 'ms
BUTTON 0,1,255,0,B1,0,ReadyLOOP
HIGH 3 'Activates Solenoid
PAUSE Dwell
LOW 3 'Deactivates Solenoid
PAUSE Drop
GOTO EYEOFF
END
CEYEON:
IR_DETECT VAR BIT
LOW 7
PAUSE 50
FREQOUT 7, 1, 38500
IR_DETECT = IN8
IF IR_DETECT = 1 THEN BROKEN
BROKEN:
IF IR_DETECT = BROKEN THEN
DIRS=11001011 'Input/Output
PINS=10000011 'Low/High
SYMBOL Trigger=PIN0 'INPUT
SYMBOL Emitter=PIN1 'OUTPUT
SYMBOL Detector=PIN2 'INPUT
SYMBOL Solenoid=PIN3 'OUTPUT
SYMBOL Dwell=B4
SYMBOL Drop=B5
LET dwell=20 'ms
LET drop=20 'ms
BUTTON 0,1,255,0,B1,0,ReadyLOOP
HIGH 3 'Activates Solenoid
PAUSE Dwell
LOW 3 'Deactivates Solenoid
PAUSE Drop
GOTO EYEON
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office