Shop OBEX P1 Docs P2 Docs Learn Events
how do i use the toggle command to go to a mode? — Parallax Forums

how do i use the toggle command to go to a mode?

bobsmithbobsmith Posts: 36
edited 2004-09-16 21:01 in BASIC Stamp
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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-09-14 20:16
    From what I think you want, I don't think the Toggle Command is what you want...It sounds more like you need the Button Command and a variable to track the current mode.· If this isn't what you're looking for, then please explain why you want to use Toggle?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • bobsmithbobsmith Posts: 36
    edited 2004-09-14 21:10
    well i need away so i can push the pushbutton in so when i push the button once it goes to mode1, twice it goes to mode2, 3times it goes to mode3, 4times it goes to mode4 it the way you are saying what i want to do can you elaborate on it more

    Examples would be very helpful... Im slowsmile.gif
  • Gerry ShandGerry Shand Posts: 45
    edited 2004-09-14 21:28
    Hi Bob:

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-09-14 23:50
    Gerry pretty much elaborated on the variable part, but how you read the button will really depend on how many buttons you plan to have in all, and what else the program will be doing when it's not switching modes.· Can you elaborate on what you're trying to do?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
    ·
  • bobsmithbobsmith Posts: 36
    edited 2004-09-16 21:01
    I am making a board for a paintball gun.

    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
Sign In or Register to comment.