Momentary switch
philipad23
Posts: 44
Hi all...
I want to know how I can work with a switch that is presses and release immediately. I have the following code that I am working on:
INPUT 12
j VAR Word
Main:
IF IN12=0 THEN increase
...
..
.
GOTO main
Increase:
j=j+1
RETURN
Increment of j works only when the switch is pressed all the time..
Anyone can help me?
Thanks
I want to know how I can work with a switch that is presses and release immediately. I have the following code that I am working on:
INPUT 12
j VAR Word
Main:
IF IN12=0 THEN increase
...
..
.
GOTO main
Increase:
j=j+1
RETURN
Increment of j works only when the switch is pressed all the time..
Anyone can help me?
Thanks
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
You need to get your INPUT statement inside your loop. Next you need to initialize your variable j.· As Chris said RETURN is for use with GOSUB. Try the following. It's an endless loop that does INPUT 12 really fast. Oh yeah don't forget to DEBUG j so you· can see the result. Depending on your switch, you may have some contact bounce, so your results may vary from what you expect.
j VAR Word
j=0
Main:
input 12
IF IN12=0 THEN j=j+1
PAUSE 200
GOTO main
Btn···· PIN··· 12
total·· VAR··· Word
Reset:
· total = 0
Main:
· DO
··· total = total + ~Btn
··· DEBUG HOME, DEC total
· LOOP
· END
In truth, the total = 0 is not actually required unless you want to clear it after it as been modified, because the Stamp clears all variables to 0 on reset.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
·· Actually putting INPUT 12 inside the loop won't do anything in this code.· All the line does is make P12 an input, but since P12 is never changing direction repeatedly using this statement has no additional effect.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com