How do I poll for serial input AND check for button changes at the same time
Archiver
Posts: 46,084
If you want to keep the value of the switches while waiting for serial
input you will have to have a latch of some sort. You could use a
74C922 keyboard encoder to handle a group of pushbuttons. You could
actually use a 16 key keyboard or wire your individual switches as
such. It has debounce circuitry and a latch and a signal that tells
you when a key was pressed. You will also use fewer I/O pins. Some
people think these are a bit expensive @$7.00 but I think they are a
great time saver. Good luck.
Lee Harker
--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...>
wrote:
> I don't know if this is possible, but I'm trying to monitor the
> serial line for any input AND poll a handfull of pushbuttons
> simultaneoulsly. I have some code functions that doesn't work very
> well. If I pound on the pushbuttons I can get them to show up half
> of the time in that small window of opportunity they have to be
> recognized.
>
> I really don't want a hardware solution to this because I suck at
> electronics. However if there was some really easy way when I
press
> a pushbutton that it would stay in that state for a second or two
my
> routine would catch it. I was looking up RS Latches, but got
> horribly confused.
>
>
> The relevant code I have follows:
>
>
> WaitForCommand:
>
> 'First check for inputs from the computer
> Mode = 0
> SERIN RxD,Baud96,2000,ReadButtons,[noparse][[/noparse]WAIT ("?"), Mode,OutputID]
> 'waits for a ? to signal start then reads Mode, and OutputID
> '# to change
>
> IF Mode = "T" THEN ToggleIt 'Toggle the Output
> IF Mode = "N" THEN TurnOn 'Turn On the Output
> IF Mode = "O" THEN TurnOff 'Turn Off the Output
> IF Mode = "S" Then StateOfButtons 'Return State
>
> GOTO ReadButtons 'If no inputs from serial, check buttons
> 'connected to the Stamp
>
> ReadButtons:
> BUTTON 6,0,255,10,buttonData0,1,Button0
> BUTTON 7,0,255,10,buttonData1,1,Button1
> BUTTON 8,0,255,10,buttonData2,1,Button2
> BUTTON 9,0,255,10,buttonData3,1,Button3
> BUTTON 10,0,255,10,buttonData4,1,Button4
> BUTTON 11,0,255,10,buttonData5,1,Button5
> BUTTON 12,0,255,10,buttonData6,1,Button6
> BUTTON 13,0,255,10,buttonData7,1,Button7
>
>
> SEROUT Txd,Baud96,[noparse][[/noparse]"Nothing"] 'just for debugging
> GOTO WaitForCommand
>
> Button0:
> --do something because button 0 was pressed
> GOTO WaitForCommand
>
>
>
> THANKS IF YOU CAN HELP!
input you will have to have a latch of some sort. You could use a
74C922 keyboard encoder to handle a group of pushbuttons. You could
actually use a 16 key keyboard or wire your individual switches as
such. It has debounce circuitry and a latch and a signal that tells
you when a key was pressed. You will also use fewer I/O pins. Some
people think these are a bit expensive @$7.00 but I think they are a
great time saver. Good luck.
Lee Harker
--- In basicstamps@yahoogroups.com, "Josh Polk" <mcstampfunk3@y...>
wrote:
> I don't know if this is possible, but I'm trying to monitor the
> serial line for any input AND poll a handfull of pushbuttons
> simultaneoulsly. I have some code functions that doesn't work very
> well. If I pound on the pushbuttons I can get them to show up half
> of the time in that small window of opportunity they have to be
> recognized.
>
> I really don't want a hardware solution to this because I suck at
> electronics. However if there was some really easy way when I
press
> a pushbutton that it would stay in that state for a second or two
my
> routine would catch it. I was looking up RS Latches, but got
> horribly confused.
>
>
> The relevant code I have follows:
>
>
> WaitForCommand:
>
> 'First check for inputs from the computer
> Mode = 0
> SERIN RxD,Baud96,2000,ReadButtons,[noparse][[/noparse]WAIT ("?"), Mode,OutputID]
> 'waits for a ? to signal start then reads Mode, and OutputID
> '# to change
>
> IF Mode = "T" THEN ToggleIt 'Toggle the Output
> IF Mode = "N" THEN TurnOn 'Turn On the Output
> IF Mode = "O" THEN TurnOff 'Turn Off the Output
> IF Mode = "S" Then StateOfButtons 'Return State
>
> GOTO ReadButtons 'If no inputs from serial, check buttons
> 'connected to the Stamp
>
> ReadButtons:
> BUTTON 6,0,255,10,buttonData0,1,Button0
> BUTTON 7,0,255,10,buttonData1,1,Button1
> BUTTON 8,0,255,10,buttonData2,1,Button2
> BUTTON 9,0,255,10,buttonData3,1,Button3
> BUTTON 10,0,255,10,buttonData4,1,Button4
> BUTTON 11,0,255,10,buttonData5,1,Button5
> BUTTON 12,0,255,10,buttonData6,1,Button6
> BUTTON 13,0,255,10,buttonData7,1,Button7
>
>
> SEROUT Txd,Baud96,[noparse][[/noparse]"Nothing"] 'just for debugging
> GOTO WaitForCommand
>
> Button0:
> --do something because button 0 was pressed
> GOTO WaitForCommand
>
>
>
> THANKS IF YOU CAN HELP!