how do i use the toggle command to go to a mode?
bobsmith
Posts: 36
how do i use the toggle command to go to a mode? so when i have 4 modes in my code i can push my pushbutton once and it goes to mode 1 and then twice to mode 2, 3 times to mode3, and 4 times to mode 4?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
Examples would be very helpful... Im slow
What I would do is set up a variable the size of a byte or nibble (large enough to hold the maximum value).
Then set up an initialization part of the program where the variable value is zero.
Then as you push the button, you can invoke a subroutine where you can add one to the variable like so:
Variable=Variable+1
If you have another button, it can be set up to go to a subroutine to set the Variable=0 so it acts as a reset; or you can set up the subroutine so that if you are at the maximum value, you can go right back to the first mode of operation.
Of course it would help to have some kind of visual indication to show what mode you are in or it could become a guessing game.
If you have a noisy circuit with pushbuttons you can always try a tantalum filter capacitor along with the pull-up/pull-down resistor.
Hope this helps. Let me know if you need any further information.
Regards,
Gerry Shand
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Knight Designs
324 West Main Street
P.O. Box 97
Montour Falls, NY 14865
(607) 535-6777
Business Page:·· http://www.knightdesigns.com
Personal Page:··· http://www.lightlink.com/dream/chris
Designs Page:··· http://www.lightlink.com/dream/designs
·
I want it so that when it is powered up it says the first part of the code bellow. Then eyeoff, eyeon, ceyeoff, and ceyeon are the 4 modes that I want. I will be attaching a button to the stamp so when I push that button it go to eyeoff then when I push the button again it goes to eyeon, then again to ceyeoff, and again to ceyeon. Then it repeats that as the button is pushed.
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