Shop OBEX P1 Docs P2 Docs Learn Events
Button input conditioned on time — Parallax Forums

Button input conditioned on time

ddemosddemos Posts: 2
edited 2009-07-09 02:34 in BASIC Stamp
Hi,

I am trying to understand how to program a bs1 to run a program in a loop with a button input to trigger the start and stop of the program, over and over, a toggle if you will. However I only want the stamp to react to the button if it has been pressed and held down for 10 seconds. It is the timing on the button trigger pin I don't understand how to complete. Any help from someone with knowledge on how to do this would be appreciated. Thanks in advance.

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2009-07-07 00:51
    ·
    ·ddemos

    ·Main:
    ·IF Button = 0 then Buttonpressed···· ' Button was pressed , GOTO Buttonpressed
    ·IF Button = 1 then Main················· ' No Button, Fall Through to GOTO Main

    ·GOTO Main

    ·Buttonpressed:
    ·x = 1·········································· 'This is a counter
    ·DO
    ·x = x + 1····································· 'x=x+1·· This adds "1" to x on every pass
    ·pause 1000·································· 'This is the time delay per pass "1000"= 1 Sec
    ·IF x > 10000 then ButtonAction······· 'When x = 10000 the time delay is 10sec
    ·LOOP

    ·ButtonAction:····································· 'This is what to do after the 10secs
    ·HIGH 15·································· 'Turn on a LED hooked to pin 15· 'this is just a demo code to lite and led
    ·PAUSE 100······························ 'Wait for 100 uSec··············· "this waits for 100 milasec
    ·LOW 15·································· 'Turn off LED hooked to pin 15···· "this turns off the led

    ·GOTO Main



    ·
    This should work with the BS1


    ·____________$WMc%________


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA

    Post Edited ($WMc%) : 7/7/2009 1:41:27 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-07-08 01:13
    I use this routine when ever I want a PIN· state to be a (1) for period of time if it changes state to (0) then it resets the counter to·(·0·)

    If it has not reach the count that you have set·in ·(cntr = ____)

    There is a way to do it with PIN state =· 0 instead of 1

    If you need that just let me know

    I know that this works·for a BS2 but· maybe you can·get this·to work



    ' {$STAMP BS2}

    ' {$PBASIC 2.5}

    chg····· PIN···· ·1

    cntr···· VAR···· Byte···· ·' Loop Counter

    DO

    cntr = cntr + 1 * Chg

    IF (cntr = 100) THEN EXIT········ ·' (cntr = ____) Can be for how ever long you want the the delay to be before it··

    ············································· ' gose to what ever routine··that·you want·········································

    LOOP

    It compiles but I do not know if this will work or not

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}



    INPUT 1

    ·SYMBOL· cntr = B1

    main:
    cntr =· cntr + 1 * PIN1


    IF· cntr = 100 THEN···exit···········' or any other routine that you want
    RETURN

    exit:

    ' your code

    RETURN

    If this routine works for you PLEASE ley me know Thank You

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 7/8/2009 1:47:22 AM GMT
  • ddemosddemos Posts: 2
    edited 2009-07-08 06:47
    Thanks for everyone's help. Sam.Sam.Sam, I was unable to get the code to work on the BS1, for some unknown reason. $WMc%, The DO statement doesn't seem to work on the BS1. The incremental counter was a key piece to the puzzle, however. I was able to get the following code to work in a manor I needed, i.e. it starts the flashing routine under "ButtonAction" on Pin 0 if the button on Pin 1 is pushed and held, it also stops the routine, if running, if the button is again pushed and held:

    ' {$STAMP BS1}
    LET DIRS = %10000000
    LET PINS = %00000000
    SYMBOL X = B2
    Main:
    IF PIN1 = 0 THEN Buttonpressed
    GOTO Main
    Buttonpressed:
    FOR X = 1 TO 10
    PAUSE 1000
    IF X = 10 THEN ButtonAction
    NEXT
    GOTO Main

    ButtonAction:
    HIGH 0
    PAUSE 100
    LOW 0
    PAUSE 1000
    HIGH 0
    PAUSE 100
    LOW 0
    PAUSE 500
    HIGH 0
    PAUSE 100
    LOW 0
    PAUSE 2500
    HIGH 0
    PAUSE 100
    LOW 0
    PAUSE 50
    IF PIN1 = 0 THEN PressedAgain
    GOTO ButtonAction

    PressedAgain:
    FOR X = 1 TO 10
    PAUSE 1000
    IF X = 10 THEN Main
    NEXT
    GOTO ButtonAction
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-07-08 20:58
    Try this one I had a few mistake in one that posted yesterday'
    ·This should work Please let me know if it dose or dose not work Thanks

    ·{$STAMP BS1}
    ' {$PBASIC 1.0}

    ·SYMBOL· cntr = B1

    Reset:
    · PINS = %00000000····························· ' clear all
    · DIRS = %11111101····························· ' set output pins

    Main:
    cntr = 0

    Trigger:
    cntr =· cntr + 5 * PIN1
    IF cntr < 100 THEN Trigger

    ' Your code

    GOTO main



    What happen to your routine if let say you only hold the button for five seconds instead of ten seconds


    ·Main:
    IF PIN1 = 0 THEN Buttonpressed

    GOTO Main

    Buttonpressed:
    FOR X = 1 TO 10
    PAUSE 1000

    IF X = 10 THEN ButtonAction
    NEXT
    GOTO Main

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 7/8/2009 9:28:54 PM GMT
  • $WMc%$WMc% Posts: 1,884
    edited 2009-07-09 02:34
    ddemos

    COOL : nice little code!




    ________$WMc%___________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
Sign In or Register to comment.