how to create modes?
bobsmith
Posts: 36
How do i create modes so i can have like 4 different modes that my pushbuttons can select to use by using the toggle command?
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