Shop OBEX P1 Docs P2 Docs Learn Events
How do I connect a switch to act as the reset button on my board of education — Parallax Forums

How do I connect a switch to act as the reset button on my board of education

mimicmimic Posts: 1
edited 2007-10-21 15:12 in BASIC Stamp
I have a program that turns a servo counterclockwise so many pulses and then clockwise so many pulses.
I want to have a switch that will start the program every time I hit the switch or button.
Here is the code for my servo· I am sure that I will have to add to it to make the button work.
Any advice
·' What's a Microcontroller - ServoTest.bs2
' Test the servo at three different position signals.
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 1000
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 500
PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
DEBUG "All done."
END

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-10-21 02:11
    On the BOE press the little button just above the power switch (marked reset)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Desy2820Desy2820 Posts: 138
    edited 2007-10-21 10:19
    Wire a button as explained in the WAM text or on pages 141-143 of the PBASIC Reference Manual.· I can't test this program, as I'm far away from my hardware, but it should work.· When running, it will sit there and do nothing until you press the button.· Once the button is pressed, the servo routine will run, then it'll wait for another button press.· Please note that pressing the button while the servos are moving will do nothing!· It will only read the button again once the servo move routine is completed.

    There are other, maybe simpler ways to do this too, such as using INPUT, with a DO WHILE or DO UNTIL type of loop.· It's up to you, this is just a suggestion.



    ' What's a Microcontroller - ServoTest.bs2 with pushbutton control
    ' Test the servo at three different position signals.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    PressMe PIN 14·· 'change to reflect pin number of your button.
    State1 CON·1·····'change to reflect button's pressed state, 0 or 1, see BUTTON command for more info, this·assumes button is wired to VDD
    State2 CON 1·····'for this example, don't change, we want to branch only if the button is pressed.
    BtnWork VAR WORD·· ·'workspace for BUTTON command
    counter VAR Word····· 'orginal program variable

    MAIN:
    DO
    BUTTON, PressMe, State1, 255, 20, BtnWork, State2, SERVO
    LOOP


    SERVO:
    DEBUG "Counterclockwise 10 o'clock", CR
    FOR counter = 1 TO 150
    PULSOUT 14, 1000
    PAUSE 20
    NEXT
    DEBUG "Clockwise 2 o'clock", CR
    FOR counter = 1 TO 150
    PULSOUT 14, 500
    PAUSE 20
    NEXT
    DEBUG "Center 12 o'clock", CR
    FOR counter = 1 TO 150
    PULSOUT 14, 750
    PAUSE 20
    NEXT
    DEBUG "All done."
    RETURN

    Post Edited (Desy2820) : 10/21/2007 10:28:56 AM GMT
  • D FaustD Faust Posts: 608
    edited 2007-10-21 15:12
    You could have a normally closed switch between your power supply and boe.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
Sign In or Register to comment.