Shop OBEX P1 Docs P2 Docs Learn Events
how to create modes? — Parallax Forums

how to create modes?

bobsmithbobsmith Posts: 36
edited 2004-09-16 21:46 in BASIC Stamp
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

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-16 05:03
    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
  • bobsmithbobsmith Posts: 36
    edited 2004-09-16 20:56
    how will I be able to select the modes in this code below through a push button with the way you are saying.

    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 WilliamsJon Williams Posts: 6,491
    edited 2004-09-16 21:03
    You're mixing BS1 and BS2 code statements. Which micro are you running on? You've also got severl incomplete statements....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobsmithbobsmith Posts: 36
    edited 2004-09-16 21:38
    i know alot of them are incorrect and incomplete. This is the first time I ever programmed. I will be using a bs2
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-16 21:46
    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
Sign In or Register to comment.