Shop OBEX P1 Docs P2 Docs Learn Events
making the stamp recognize photo transistors — Parallax Forums

making the stamp recognize photo transistors

v_2hbranv_2hbran Posts: 4
edited 2008-01-02 17:21 in Learn with BlocklyProp
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

Comments

  • jmalaysiajmalaysia Posts: 97
    edited 2007-12-25 21:07
    At the beginning of Main_Loop you are setting the counter=0, then immediately adding 1 to it, making counter=1. Then, lets say IR_tripped_1 is true (which it would have to be to ever escape the Do_Loop). So you add 50 to the total then send it by Goto to Check_Total. At this point Counter is 1, right? The statement If Counter<3 then Goto Main_Loop sends it back to the top of Main_Loop, at which point you are setting counter=0 once again, which loses your count, meaning you will never reach 3 and display the total.

    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.
  • FranklinFranklin Posts: 4,747
    edited 2007-12-26 01:07
    The best way to help us is to 'attach' the code to your post so it can be loaded and run if needed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • David H.David H. Posts: 78
    edited 2008-01-02 17:21
    Alv_2hbran,
    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!!!
Sign In or Register to comment.