Alternative to BUTTON ??
Archiver
Posts: 46,084
Here's one approach. Let's assume your switches are attached to
I/O's 0 through 11 (if you've got plenty of I/O pins to use up this
way, might at well write code that uses 'em efficiently).
lastINS VAR WORD
thisINS VAR WORD
lastINS = $FFFF ' ensure mismatch at start
mainLoop:
{check for SERIN and do whatever else needs doing)
thisINS = INS & $0FFF ' current switch settings in thisINS
IF thisINS = lastINS THEN main
lastINS = thisINS
SEROUT pin,baud,[noparse][[/noparse]thisINS.LOWBYTE, thisINS.HIGHBYTE]
GOTO mainLoop
This sends two bytes to the PC at startup and whenever the switch
settings change. Let the PC look at the bit settings and figure out
which switch changed to which value--it's probably easier and more
convenient to do in your PC program and this lets your Stamp
concentrate on what you need it to be doing.
Regards,
Steve
On 31 May 01 at 14:29, percy@i... wrote:
> Is there an alternative way of reading a switch to the BUTTON
> command ? I need to read a switch and transmit this data to a PC
> serially, but only when the switch state changes. I am currently
> doing this using INS e.g. comparing INS to say INS.bit1 and if a
> change has ocurred transmitting a byte to the PC in the format of :
> 10 (switch open) and 11 (switch closed) switch 2 would be : 20
> (switch open) and 21 (switch closed). This appears to work ok for a
> couple of switches, but with 12 switches involved, transmitting a
> byte per switch, the Stamp (a BS2SX), can get tied up and ignore
> serial commands transmitted to it. Also, the state of a switch needs
> to be read upon system startup, transmitting this state to the PC,
> without the switch changing state.
>
>
> Has anyone out there had a similar problem who may be able to help??
>
> Thanks
> Steve
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed with. 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/
>
>
I/O's 0 through 11 (if you've got plenty of I/O pins to use up this
way, might at well write code that uses 'em efficiently).
lastINS VAR WORD
thisINS VAR WORD
lastINS = $FFFF ' ensure mismatch at start
mainLoop:
{check for SERIN and do whatever else needs doing)
thisINS = INS & $0FFF ' current switch settings in thisINS
IF thisINS = lastINS THEN main
lastINS = thisINS
SEROUT pin,baud,[noparse][[/noparse]thisINS.LOWBYTE, thisINS.HIGHBYTE]
GOTO mainLoop
This sends two bytes to the PC at startup and whenever the switch
settings change. Let the PC look at the bit settings and figure out
which switch changed to which value--it's probably easier and more
convenient to do in your PC program and this lets your Stamp
concentrate on what you need it to be doing.
Regards,
Steve
On 31 May 01 at 14:29, percy@i... wrote:
> Is there an alternative way of reading a switch to the BUTTON
> command ? I need to read a switch and transmit this data to a PC
> serially, but only when the switch state changes. I am currently
> doing this using INS e.g. comparing INS to say INS.bit1 and if a
> change has ocurred transmitting a byte to the PC in the format of :
> 10 (switch open) and 11 (switch closed) switch 2 would be : 20
> (switch open) and 21 (switch closed). This appears to work ok for a
> couple of switches, but with 12 switches involved, transmitting a
> byte per switch, the Stamp (a BS2SX), can get tied up and ignore
> serial commands transmitted to it. Also, the state of a switch needs
> to be read upon system startup, transmitting this state to the PC,
> without the switch changing state.
>
>
> Has anyone out there had a similar problem who may be able to help??
>
> Thanks
> Steve
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed with. 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/
>
>
Comments
?
I need to read a switch and transmit this data to a PC serially, but
only when the switch state changes.
I am currently doing this using INS e.g. comparing INS to say
INS.bit1 and if a change has ocurred transmitting a byte to the PC in
the format of : 10 (switch open) and 11 (switch closed)
switch 2 would be : 20 (switch open) and 21 (switch closed).
This appears to work ok for a couple of switches, but with 12
switches involved, transmitting a byte per switch, the Stamp (a
BS2SX), can get tied up and ignore serial commands transmitted to it.
Also, the state of a switch needs to be read upon system startup,
transmitting this state to the PC, without the switch changing state.
Has anyone out there had a similar problem who may be able to help??
Thanks
Steve
percy@iinet.net.au writes:
?
I need to read a switch and transmit this data to a PC serially, but
only when the switch state changes.
I am currently doing this using INS e.g. comparing INS to say
INS.bit1 and if a change has ocurred transmitting a byte to the PC in
the format of : 10 (switch open) and 11 (switch closed)
switch 2 would be : 20 (switch open) and 21 (switch closed).
This appears to work ok for a couple of switches, but with 12
switches involved, transmitting a byte per switch, the Stamp (a
BS2SX), can get tied up and ignore serial commands transmitted to it.
Also, the state of a switch needs to be read upon system startup,
transmitting this state to the PC, without the switch changing state.
You can debounce several switches at the same time with a few lines of code,
then transmit the status as two bytes (1 bit per switch -- you'll have some
extras). ·Take a look at the StampWorks manual from Parallax. ·It has an
experiment that explains and demonstrates the method for debouncing multiple
switches.
You can download the StampWorks book as a PDF from this link:
http://www.parallaxinc.com/html_files/products/stampworks.asp
-- Jon Williams
-- Dallas, TX[/font]