Keeping Count Of Times A Button Has Been Pressed And Display them On A Serial L
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
' BUTTONCOUNTER.BS2 ' Connect an active-low circuit to pin P0 of the BS2. When you press the ' button, the DEBUG screen will display an asterisk (*). The program, as ' shown below, will print an asterisk for every button press. ' {$STAMP BS2} ' {$PBASIC 2.5} btnwrk VAR Byte counter VAR Byte check VAR Byte Main: [color=green] ' Try changing the Delay value (255) in BUTTON to see the effect of ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat; ' 255 = no auto-repeat (only one action per button press) ' ' The BUTTON instruction will cause the program to branch to ' No_Press unless P0 = 0[/color] PAUSE 10 BUTTON 0, 1, 255, 20, btnwrk, 0, No_Press : counter=counter+1 [color=green]'Add One to variable counter[/color] DEBUG HOME DEBUG "the count is:",DEC counter, CR [color=green]' Display positive count in the debug window[/color] [color=green]'When the button is no longer being pressed the program continues....[/color] No_Press: FOR check = 1 TO 10 [color=green]'Checks the status of the button ten times[/color] IF IN0 = 1 THEN GOTO Main [color=green]'If the button is being pressed GOTO the main routine and start over[/color] PAUSE 60 [color=green]'This pause gives the loop enough time to see if the button[/color][color=green]- [/color]NEXT [color=green]'-is actually being pressed[/color] [color=green]'If the loop does not detect further button presses then the program continues....[/color] DO WHILE counter >= 1 [color=green]'Subtract One from variable counter and loop until counter equals zero[/color] counter = counter - 1 PAUSE 100 DEBUG HOME DEBUG "the count is:",DEC counter, CR [color=green]' Display negative count in the debug window[/color] LOOP GOTO Main [color=green]'Start back at the beginning[/color]▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What if there was nothing? Nothing is something!