making the stamp recognize photo transistors
v_2hbran
Posts: 4
We are trying to·make it so that the photo transistors can only be tripped 3 times before giving a total.· Each one has been assigned a certain point value.· We are only beginners, and so far we can make the sensors recognize that something has passed in front of them and they will then give a point value, but our counter is not counting up· so they never actually come to a total.· our code is as follows and works other than the total and counter option:
' {$STAMP BS2}
' {$PBASIC 2.5}
IR_tripped_1·· PIN 4
IR_tripped_2·· PIN 3
IR_tripped_3·· PIN 6
sensor_1 CON 50
sensor_2 CON 75
sensor_3 CON 100
lcdcls CON $0C
Baud19200 CON 32
total VAR Word
Counter VAR Nib
·Restart:···· 'Come here on a restart (if required), to zero out total
FOR Counter = 0 TO 3
DO
total = 0
DEBUG HOME
DEBUG ? Counter
DEBUG ? IN4
DEBUG ? IN3
DEBUG ? IN6
Main_Loop:
· DO
· Counter = 0
· Counter = Counter + 1
·IF (IR_tripped_1 = 0) THEN
·HIGH 14
·PAUSE 1000
·LOW 14
·DEBUG "50 points."
·total = total + sensor_1
·GOTO Check_Total
· ENDIF
· LOOP
·DO
·Counter = Counter + 1
·IF (IR_tripped_2 = 0) THEN
·HIGH 4
·PAUSE 1000
·LOW 4
·DEBUG "75 points."
·total = total + sensor_2
·GOTO Check_Total
·ENDIF
·LOOP
·DO
·Counter = Counter + 1
·IF (IR_tripped_3 = 0) THEN
·DEBUG "100 points."
·total = total + sensor_3
·ENDIF
·LOOP
GOTO Main_Loop
·LOOP UNTIL Counter = 3
NEXT
·PAUSE 500
Check_Total:
IF Counter < 3 THEN
·GOTO Main_Loop:
ELSEIF (Counter = 3)· THEN
·DEBUG " your score is:", DEC total, CR
ENDIF
Any suggestions?· We've been trying the "What is a Microcontroller?" pdf, but we haven't been able to implement their examples into our code,
Thanks
' {$STAMP BS2}
' {$PBASIC 2.5}
IR_tripped_1·· PIN 4
IR_tripped_2·· PIN 3
IR_tripped_3·· PIN 6
sensor_1 CON 50
sensor_2 CON 75
sensor_3 CON 100
lcdcls CON $0C
Baud19200 CON 32
total VAR Word
Counter VAR Nib
·Restart:···· 'Come here on a restart (if required), to zero out total
FOR Counter = 0 TO 3
DO
total = 0
DEBUG HOME
DEBUG ? Counter
DEBUG ? IN4
DEBUG ? IN3
DEBUG ? IN6
Main_Loop:
· DO
· Counter = 0
· Counter = Counter + 1
·IF (IR_tripped_1 = 0) THEN
·HIGH 14
·PAUSE 1000
·LOW 14
·DEBUG "50 points."
·total = total + sensor_1
·GOTO Check_Total
· ENDIF
· LOOP
·DO
·Counter = Counter + 1
·IF (IR_tripped_2 = 0) THEN
·HIGH 4
·PAUSE 1000
·LOW 4
·DEBUG "75 points."
·total = total + sensor_2
·GOTO Check_Total
·ENDIF
·LOOP
·DO
·Counter = Counter + 1
·IF (IR_tripped_3 = 0) THEN
·DEBUG "100 points."
·total = total + sensor_3
·ENDIF
·LOOP
GOTO Main_Loop
·LOOP UNTIL Counter = 3
NEXT
·PAUSE 500
Check_Total:
IF Counter < 3 THEN
·GOTO Main_Loop:
ELSEIF (Counter = 3)· THEN
·DEBUG " your score is:", DEC total, CR
ENDIF
Any suggestions?· We've been trying the "What is a Microcontroller?" pdf, but we haven't been able to implement their examples into our code,
Thanks
Comments
I'm not sure what the For Counter=0 to 3 does for you since there is no Next statement.
It's pretty hard to figure out what people intend just by reading the code, but I think a single Do_Loop will take care of your needs from what I can tell. Put all your If_Then statements in one loop, with a Counter=Counter+1 prior to the End_if for each case, then break out of the loop if Counter=3.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Also, I see in your Main_loop: you have 3 DO-LOOPs, and I believe once your first DO-LOOP is executed, the rest will always be ignored.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
David
There are 10 types of people in this world,...
Those that understand binary numbers, and those that don't!!!