How to detect an on/off switch
Archiver
Posts: 46,084
Hi Everyone,
What's the simplest way for my PC to detect (through a Basic Stamp
2SX) changes in an on/off switch? I have pushbuttons down, but I
need my PC to know when there is a change of state. I have four
switches. Thanks!
-Josh
What's the simplest way for my PC to detect (through a Basic Stamp
2SX) changes in an on/off switch? I have pushbuttons down, but I
need my PC to know when there is a change of state. I have four
switches. Thanks!
-Josh
Comments
There is a great tutorial on same in free Parallax downloadable
books.
Also, you didn't indicate what TYPE of switch. Are you trying to
detect the on/off of an appliance (i.e. 110VAC) or the on/off of a
pushbutton?
In the case of the latter, see the below referenced book (free
download) on detecting the state of a pushbutton and subsequently
illuminating an LED.
Ref: What's a Microcomputer, pg 80, Chap 3, Activity 3
"Pushbutton Control of an LED Circuit"
http://www.parallax.com/dl/docs/books/edu/wamv2_1.pdf
--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...>
wrote:
> Hi Everyone,
>
> What's the simplest way for my PC to detect (through a Basic Stamp
> 2SX) changes in an on/off switch? I have pushbuttons down, but I
> need my PC to know when there is a change of state. I have four
> switches. Thanks!
>
> -Josh
transistor / relay. Or am I missing the point completely :-)
http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf
--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...>
wrote:
> Hi Everyone,
>
> What's the simplest way for my PC to detect (through a Basic Stamp
> 2SX) changes in an on/off switch? I have pushbuttons down, but I
> need my PC to know when there is a change of state. I have four
> switches. Thanks!
>
> -Josh
light switches that I'm connecting to the Stamp as inputs. When I
flip the switch from on to off I need the Stamp to know it. I guess
I can just read the state of the pins in a loop... maybe it's
simpler than I thought. I'll figure something out.
--- In basicstamps@yahoogroups.com, "johncouture" <basicstamp@j...>
wrote:
> Another thought, See Nuts & Volts Issue #6 on how to switch a
> transistor / relay. Or am I missing the point completely :-)
>
> http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf
>
> --- In basicstamps@yahoogroups.com, "Josh Polk"
<mcstampfunk3@y...>
> wrote:
> > Hi Everyone,
> >
> > What's the simplest way for my PC to detect (through a Basic
Stamp
> > 2SX) changes in an on/off switch? I have pushbuttons down, but
I
> > need my PC to know when there is a change of state. I have four
> > switches. Thanks!
> >
> > -Josh
required to check four switches?
It can be done with discrete logic (gates, flip-flops, etc.) but this
seems to be overkill for what you seem to want to do. If timing is
really a problem, set up the code to only check once every so often
(for example, once for every ten passes through the "main" loop).
Russ
--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...> wrote:
>
> That's not what I'm trying to do. Basically I have four on/off
> light switches that I'm connecting to the Stamp as inputs. When I
> flip the switch from on to off I need the Stamp to know it. I guess
> I can just read the state of the pins in a loop... maybe it's
> simpler than I thought. I'll figure something out.
>
> --- In basicstamps@yahoogroups.com, "johncouture" <basicstamp@j...>
> wrote:
> > Another thought, See Nuts & Volts Issue #6 on how to switch a
> > transistor / relay. Or am I missing the point completely :-)
> >
> > http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf
> >
> > --- In basicstamps@yahoogroups.com, "Josh Polk"
> <mcstampfunk3@y...>
> > wrote:
> > > Hi Everyone,
> > >
> > > What's the simplest way for my PC to detect (through a Basic
> Stamp
> > > 2SX) changes in an on/off switch? I have pushbuttons down, but
> I
> > > need my PC to know when there is a change of state. I have four
> > > switches. Thanks!
> > >
> > > -Josh
MainLoop:
OldNibble = Nibble
Nibble = INA
If OldNibble <> Nibble then ChangeOfState
goto MainLoop
ChangeOfState:
(Do something here)
goto MainLoop
>What else is the Stamp doing that you're so concerned with the time
>required to check four switches?
>
>It can be done with discrete logic (gates, flip-flops, etc.) but this
>seems to be overkill for what you seem to want to do. If timing is
>really a problem, set up the code to only check once every so often
>(for example, once for every ten passes through the "main" loop).
>
>Russ
>
>--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...> wrote:
> >
> > That's not what I'm trying to do. Basically I have four on/off
> > light switches that I'm connecting to the Stamp as inputs. When I
> > flip the switch from on to off I need the Stamp to know it. I guess
> > I can just read the state of the pins in a loop... maybe it's
> > simpler than I thought. I'll figure something out.
> >
> > --- In basicstamps@yahoogroups.com, "johncouture" <basicstamp@j...>
> > wrote:
> > > Another thought, See Nuts & Volts Issue #6 on how to switch a
> > > transistor / relay. Or am I missing the point completely :-)
> > >
> > > http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf
> > >
> > > --- In basicstamps@yahoogroups.com, "Josh Polk"
> > <mcstampfunk3@y...>
> > > wrote:
> > > > Hi Everyone,
> > > >
> > > > What's the simplest way for my PC to detect (through a Basic
> > Stamp
> > > > 2SX) changes in an on/off switch? I have pushbuttons down, but
> > I
> > > > need my PC to know when there is a change of state. I have four
> > > > switches. Thanks!
> > > >
> > > > -Josh
>
>
>
>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.
>
>Yahoo! Groups Links
>
>
>
>
Beau Schwabe Mask Designer National Semiconductor Corporation
500 Pinnacle Court, Suite 525
Home: polygon_man@h... Mail Stop GA1
Work: bschwabe@a... Norcross, GA 30071
'put pullup resistors (4.7K) on ports 1 to 4
'set stamp version
'define any variables
loop:
low 5 'resets the outputs to off condition
low 6
low 7 'etc.
if in1 = 0 then relay1 'check state of pushbutton 1
if in2 = 0 then relay2 'etc.
if in3 = 0 then relay3 'etc.
in in4 = 0 then relay4 'etc.
goto loop 'if no buttons are pressed, look again
relay1:
high 5 'output port 5 to trigger transistor/relay
'if you want relay to stay ln a while, insert pause here
'or jump to a subroutine for a delay
return
relay2:
high 6 'etc.
return
relay3:
high 7 'etc
return
etc.
etc.
check out this web site for schematics/hardware to drive relays, valves,
motors, etc.
jim http://www.geocities.com/jimforkin2003/
Original Message
From: johncouture [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=foXaz-jFeWX3Nv0_p7WNnCnO1kVqbPrSQ9hExeiUWBGI28ZpbYdCCrasIgdPrOZG-ZewHt8UCOsJ9iP23oox]basicstamp@j...[/url
Sent: Wednesday, May 12, 2004 2:06 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Re: How to detect an on/off switch
Another thought, See Nuts & Volts Issue #6 on how to switch a
transistor / relay. Or am I missing the point completely :-)
http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv6.pdf
--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...>
wrote:
> Hi Everyone,
>
> What's the simplest way for my PC to detect (through a Basic Stamp
> 2SX) changes in an on/off switch? I have pushbuttons down, but I
> need my PC to know when there is a change of state. I have four
> switches. Thanks!
>
> -Josh
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.
Yahoo! Groups Links