Counting
Here is my program. how can I make it faster and can I label the debug sereen: People in total, People out, people in store.
' {$STAMP BS2}
' {$PBASIC 2.5}
'Two counters one for people entering and one for leaving.
'The difference "C" is the number of people in the store
CounterA VAR Word 'People entering store total
CounterB VAR Word 'People leaving store
C VAR Word 'People in store
DO
DEBUG HOME
DEBUG CLS
DEBUG DEC CounterA, CR
DEBUG DEC COUNTERB, CR
DEBUG DEC C, CR
IF (IN3 = 1) THEN
CounterA = CounterA + 1 'People entering store total count
PAUSE 500
ENDIF
IF (IN4 = 1) THEN
CounterB = CounterB + 1 'People leaving store total count
PAUSE 500
ENDIF
C = CounterA - CounterB 'People in the store
PAUSE 1000
LOOP
END
' {$STAMP BS2}
' {$PBASIC 2.5}
'Two counters one for people entering and one for leaving.
'The difference "C" is the number of people in the store
CounterA VAR Word 'People entering store total
CounterB VAR Word 'People leaving store
C VAR Word 'People in store
DO
DEBUG HOME
DEBUG CLS
DEBUG DEC CounterA, CR
DEBUG DEC COUNTERB, CR
DEBUG DEC C, CR
IF (IN3 = 1) THEN
CounterA = CounterA + 1 'People entering store total count
PAUSE 500
ENDIF
IF (IN4 = 1) THEN
CounterB = CounterB + 1 'People leaving store total count
PAUSE 500
ENDIF
C = CounterA - CounterB 'People in the store
PAUSE 1000
LOOP
END
Comments
DEBUG HOME, DEC5 CounterA, CR
DEBUG DEC5 CounterB, CR
DEBUG DEC5 C, CR
You could also put the labels on the line above by having an initialization line before the DO
DEBUG HOME, CLS, "Enter Leave Total"
Then the display stuff would be
DEBUG HOME, LF, DEC5 CounterA, " ", DEC5 CounterB, " ", DEC5 C
Thanks joe
newIn3 = in3
if (oldIn3 = 0) and (newIn3 = 1) then
countA = countA + 1
endif
oldIn3 = newIn3
Both oldIn3 and newIn3 are defined as bit variables and oldIn3 is initialized to zero.
Joe
Display:
DEBUG HOME, LF, DEC5 CounterA, " ", DEC5 CounterB, " ", DEC5 C
CheckButton:
BUTTON 3, 1, 255, 0, Work3, 1, Pushed3 ' Check buttons
BUTTON 4, 1, 255, 0, Work4, 1, Pushed4
GOTO CheckButton ' No need to display if nothing changed
Pushed3:
CountA = CountA + 1
C = C + 1
GOTO Display ' No need to check IN4 this cycle ... will be checked after display update
Pushed4:
CountB = CountB + 1
C = C + 1
GOTO Display
I think I got the BUTTON parameters right. Check the Stamp Manual description. We're debouncing only, no auto-repeat. Work3 and Work4 are byte variables.
' {$STAMP BS2}
' {$PBASIC 2.5}
Btn1 PIN 3
Btn2 PIN 4
btnWrk1 VAR Byte
btnwrk2 VAR Byte
DO
PAUSE 5
BUTTON Btn1, 1, 255, 255, btnWrk1, 0, No_Press
DEBUG "*"
BUTTON Btn2, 1, 255, 255, btnWrk2, 0, No_Press
DEBUG "#"
No_Press:
LOOP
' {$STAMP BS2}
' {$PBASIC 2.5}
'Two counters one for people entering one door, and one for
'People leaving through the other door
'The difference "C" is the number of people in the store
CounterA VAR Word 'People entering store total
CounterB VAR Word 'People leaving store
C VAR Word 'People in store
DO
DEBUG HOME, CR
DEBUG DEC3 CounterA,"-ENTERED STORE - Daily Total",CR
DEBUG DEC3 COUNTERB,"-LEFT STORE", CR
DEBUG DEC3 C,"-ARE IN STORE", CR
IF (IN3 = 1) THEN
CounterA = CounterA + 1 'People entering store total count
PAUSE 500
ENDIF
IF (IN4 = 1) THEN
CounterB = CounterB + 1 'People leaving store total count
PAUSE 500
ENDIF
C = CounterA - CounterB 'People in the store
PAUSE 20
LOOP:
END