button state change
Hi guys, a simple question
I have a stamp1 that I want to trigger a transmitter on an input
state change. When the input goes high, I want to trigger one event,
when it goes low, I want to trigger a different event. I only want
the event to happen once for a state change, not continuously.
Anybody have a "simple" way to do this?
Thanks
Jody
I have a stamp1 that I want to trigger a transmitter on an input
state change. When the input goes high, I want to trigger one event,
when it goes low, I want to trigger a different event. I only want
the event to happen once for a state change, not continuously.
Anybody have a "simple" way to do this?
Thanks
Jody
Comments
Btnin var in0
Laststate var nib
Laststate = $F ' impossible state
Loop:
If Btnin=0 then Btnz
If Laststate=1 then Loop ' same old state
' Do what you want for a "1" state
Laststate=1
Pause 1 ' may need some debounce delay or may not if your task is long
enough
Goto Loop
Btnz:
If Laststate=0 then Loop
' Do what you want for the "0" state
Laststate=0
Pause 1 ' optional debounce delay
Goto Loop
That ought to do it, if I correctly understand what you want.
Real switches tend to bounce. That is they, don't go: 000000111111 but
they go 0000010101011111111, to debounce it, you need some delay between
samplings that change state. If your task takes long enough, this may
take care of itself. Otherwise, experiment with the pause values in the
code above.
Al Williams
AWC
* Easy RS-232 Prototyping
http://www.al-williams.com/awce/rs1.htm
>
Original Message
> From: moparjody [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=4u-fZy8_sXTB3-Tx3UwfVE3j5XSC_s_PYM7NLxYUfYhfpLCGyivzFsu7k2nanJUAGBt5yoOdO06331mRKJ4d]jody.gallant@s...[/url
> Sent: Wednesday, January 09, 2002 8:03 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] button state change
>
>
> Hi guys, a simple question
>
> I have a stamp1 that I want to trigger a transmitter on an input
> state change. When the input goes high, I want to trigger one event,
> when it goes low, I want to trigger a different event. I only want
> the event to happen once for a state change, not continuously.
>
> Anybody have a "simple" way to do this?
>
> Thanks
> Jody
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
old var bit
loop:
new=in0
if new^old&new then X01
if new^old&old then X10
old=new
goto loop
X01:
' do this on 0-->1 transition
X10:
' do this on 1-->0 transition
Put a capacitor in parallel the button circuit to debounce it.
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
Keep track of the pin state like this:
Oldstate var bit
Newstate var bit
Oldstate=0
Newstate=0
Loop:
Oldstate=newstate
Newstate=in0 'or any other pin
If (oldstate^newstate)=1 and newstate=1 then event_on_pos_edge
If (oldstate^newstate)=1 and newstate=0 then event_on_neg_edge
Goto loop
Regards peter
Oorspronkelijk bericht
Van: moparjody [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=OBvuzZ2v_vsH_JTEYpZB2ZSYlxBia8hgBn-2VWzQSLuR_1daIzLl7FOCs3C2F0JTm8l-molO_Tj-FRqi5VAB]jody.gallant@s...[/url
Verzonden: woensdag 9 januari 2002 6:03
Aan: basicstamps@yahoogroups.com
Onderwerp: [noparse][[/noparse]basicstamps] button state change
Hi guys, a simple question
I have a stamp1 that I want to trigger a transmitter on an input
state change. When the input goes high, I want to trigger one event,
when it goes low, I want to trigger a different event. I only want
the event to happen once for a state change, not continuously.
Anybody have a "simple" way to do this?
Thanks
Jody
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/