Button input conditioned on time
ddemos
Posts: 2
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.
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
·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
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··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/8/2009 1:47:22 AM GMT
' {$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
·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··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/8/2009 9:28:54 PM GMT
COOL : nice little code!
________$WMc%___________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA