Keeping Count Of Times A Button Has Been Pressed And Display them On A Serial L
beazleybub
Posts: 102
Will someone please show me what I need to fix please.
This program detects when the push button is pressed and·adds 1·to the·variable "counter" and displays a message showing the count on a LCD. Then goes to a subroutine called Subtract: and·subtracts 1·from the variable "counter" again displaying a message showing the count being subtracted on the LCD and flashes an LED once for every time 1 is subtracted form variable "counter".
I am running into a problem with allowing more than one increment at a time before it goes to the subroutine.. And I realize that the program as written is doing exactly as it is written.
Where I am having trouble is giving the program enough time to see if there are any other button presses before going to the subroutine.
What it will do is successfully subtract 1 from variable "counter" and flash the led as many times as necessary until variable "counter" equals zero.
What it won't do is allow me to push the button say five times and count all of the presses before it goes to the subroutine to subtract them. What am I missing here? Can someone please show me what I need to add or adjust to give the program time to wait for all the button presses before it goes to the subroutine Subtract:
·Any help is appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 6/26/2008 6:55:49 AM GMT
This program detects when the push button is pressed and·adds 1·to the·variable "counter" and displays a message showing the count on a LCD. Then goes to a subroutine called Subtract: and·subtracts 1·from the variable "counter" again displaying a message showing the count being subtracted on the LCD and flashes an LED once for every time 1 is subtracted form variable "counter".
I am running into a problem with allowing more than one increment at a time before it goes to the subroutine.. And I realize that the program as written is doing exactly as it is written.
Where I am having trouble is giving the program enough time to see if there are any other button presses before going to the subroutine.
What it will do is successfully subtract 1 from variable "counter" and flash the led as many times as necessary until variable "counter" equals zero.
What it won't do is allow me to push the button say five times and count all of the presses before it goes to the subroutine to subtract them. What am I missing here? Can someone please show me what I need to add or adjust to give the program time to wait for all the button presses before it goes to the subroutine Subtract:
' {$STAMP BS2} ' {$PBASIC 2.5} counter VAR Word Main: DO DO DO:LOOP WHILE IN0 ' stays here until pin goes low PAUSE 32 LOOP WHILE IN0 ' second check that the pin is really low DO DO:LOOP UNTIL IN0 ' stays here until pin goes high PAUSE 30 LOOP UNTIL IN0 ' check it twice counter=counter+1 SEROUT 15, 84, [noparse][[/noparse]"?fthe count is:",DEC counter] ' display positive count on LCD PAUSE 3000 GOSUB Subtract LOOP Subtract: PAUSE 1000 DO WHILE counter >= 1 'loop until counter is less than 1 counter = counter - 1 HIGH 14 :PAUSE 400 :LOW 14: SEROUT 15, 84, [noparse][[/noparse]"?fthe count is:",DEC counter]'- ' -display negitive count on LCD And flash an LED LOOP GOTO Main
·Any help is appreciated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!
Post Edited (beazleybub) : 6/26/2008 6:55:49 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!