my second infra red beam wont give a value (gosub structure)

my second infra red beam wont give a value
hi all, after getting my infra red beam code working (see here final lcd ir 3 code.bas)
using steady states, have tried to structure the code around 'events' like a state machine.

now my second infra red beam will not give a value


subsystem diagram here https://docs.google.com/presentation...Gvew98sAQ/edit

current code:
Code:
'#com 4
#no_data

symbol IR1=b1 
symbol IR2=b2
symbol counter=b3


init:     
    counter=4 'start at max spaces availible
    pause 500 ; wait for display to initialise
    serout B.1,N2400,(254,1)
    pause 30



    

main:


   
'do
gosub counterbeam1
gosub counterbeam2  
   
'loop   
   
goto main




counterbeam1:

 serout B.1,N2400,(254,128)   ; move to start of first line
 serout B.1,N2400,("places availible")  ; output text   
 serout b.1, n2400, ( 254, 192 ) 'second line
 serout b.1, N2400, (#counter)
     
 readadc b.4,IR1
 debug IR1
 if IR1 <10 then goto in_the_beam  
 
goto counterbeam1
 




in_the_beam:
   readadc b.4,IR1
   debug IR1
   pause 500
   if IR1 >10 then goto out_of_the_beam
   goto in_the_beam
 

out_of_the_beam:
   let counter = counter -1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
  'return
goto main


full:
  
  debug counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2
  if IR2 <10 then goto counterbeam2

goto main 
 
 

counterbeam2:

serout B.1,N2400,(254,128)   ; move to start of first line
 serout B.1,N2400,("places availible")  ; output text   
 serout b.1, n2400, ( 254, 192 ) 'second line
 serout b.1, N2400, (#counter)
     
 readadc c.4,IR2
 debug IR2
 if IR2 <100 then goto in_the_beam2  


in_the_beam2:

readadc c.4,IR2 
   debug IR2
   pause 500
   if IR2 >100 and counter<4 then goto out_of_the_beam2
   goto in_the_beam2
 

out_of_the_beam2:
   let counter = counter +1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
goto main
 
Last edited:

rossko57

Senior Member
Can you tell us what you actually see, your debug's must be showing something?
Can you confirm which Picaxe you are using (it makes a difference for readadc)?

Have you done the obvious of swapping the connections to the two sensors temporarily, so that you can see if the sensor is working?
 

hippy

Technical Support
Staff member
The problem may be those "goto main" commands within the "counterbeam1" subroutine which restarts the main program loop without ever reaching "counterbeam2".
 

inglewoodpete

Senior Member
Put simply, if you enter a subroutine (with a GoSub statement) then you must exit the subroutine with a Return statement.
 

inglewoodpete

Senior Member
i have changed the IR2 code slightly to match the IR1 code but honestly im not sure where to put goto main or return
Use Goto Main in your main loop. Use Return when you want to exit a subroutine. So, once you enter a subroutine (with a gosub statement), don't jump out of the subroutine at any stage. Use the return statement.

...and as I've said in another thread of yours: you are skating on thin ice if you try to measure infrared with ReadADC. When summer comes, the background temperature will change. (the aforementioned thin ice will melt!:))
 
Use Goto Main in your main loop. Use Return when you want to exit a subroutine. So, once you enter a subroutine (with a gosub statement), don't jump out of the subroutine at any stage. Use the return statement.[QUOTE/]


here's what i did.

Code:
#com 4
#no_data

symbol IR1=b1 
symbol IR2=b2
symbol counter=b3


init:     
    counter=4 'start at max spaces availible
    pause 500 ; wait for display to initialise
    serout B.1,N2400,(254,1)
    pause 30



    

main:


   
'do
gosub counterbeam1
gosub counterbeam2  
   
'loop   
   
goto main




counterbeam1:

 serout B.1,N2400,(254,128)   ; move to start of first line
 serout B.1,N2400,("places availible")  ; output text   
 serout b.1, n2400, ( 254, 192 ) 'second line
 serout b.1, N2400, (#counter)
     
 readadc b.4,IR1
 debug IR1
 if IR1 <10 then goto in_the_beam  
 
goto counterbeam1
 




in_the_beam:
   readadc b.4,IR1
   debug IR1
   pause 500
   if IR1 >10 then goto out_of_the_beam
   goto in_the_beam
 

out_of_the_beam:
   let counter = counter -1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
  return



full:
  
  debug counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2
  if IR2 <10 then goto counterbeam2

goto full 
 
 

counterbeam2:

serout B.1,N2400,(254,128)   ; move to start of first line
 serout B.1,N2400,("places availible")  ; output text   
 serout b.1, n2400, ( 254, 192 ) 'second line
 serout b.1, N2400, (#counter)
     
 readadc c.4,IR2
 debug IR2
 if IR2 <50 then goto in_the_beam2  


in_the_beam2:

readadc c.4,IR2 
   debug IR2
   pause 500
   if IR2 >50 and counter<4 then goto out_of_the_beam2
   goto in_the_beam2
 

out_of_the_beam2:
   let counter = counter +1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
return




the debug screen before the IR1 is blocked then unblocked doesnt display IR2's value
only once IR1 is covered then uncovered will the screen displays the value of IR2

but once then couneter counts below 4, it counts back up without IR2 being covered
 
Last edited:

rossko57

Senior Member
the debug screen before the IR1 is blocked then unblocked doesnt display IR2's value
Might be worth printing out your program, and using your finger to follow the flow of execution.
Your 'counterbeam1' subrouting has a couple of endless loops in it, that can only be escaped from under certain conditions (like you describe observing).
Remember, Picaxe doesn't know when to end a routine and get back to where it was unless you tell it (with RETURN).
Subroutines are a powerful tool, but you do need to understand how to jump into them and how to get back to where you were.
 

techElder

Well-known member
titanium, I can follow your code through to a return in several places, however, as rosko57 says there are "traps" that need to be taken care of.

I'd bet that if you would draw out the flow chart of your program, you will see ways to improve the flow (or understanding) of it.

For instance, if something (or someone) blocks one of the beams (chewing gum? :) ), where does your code lock up? You have to take care of a situation like that.

Perhaps keep a counter/timer in each of those "goto/beginning" loops as a "timeout" error check for the loop.

Speaking of loops, have you investigated how to use the do/loop structure?

Code:
full:
  
  debug counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2
  if IR2 <10 then goto counterbeam2

goto full
Code:
do
  
  debug counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2

loop until IR2 <10
goto counterbeam2
It is easier to see what you are doing in the do/loop example.

Then you could add the error detection logic. For example,

Code:
timeout_counter = 0
do
  
  debug counter
  inc timeout_counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2

loop until IR2 <10 OR timeout_counter > some_timeout_value

if timeout_counter > some_timeout_value then
   go to ERROR_STOP
else
   goto counterbeam2
endif
 
Code:
 '#com 4
#no_data

symbol IR1=b1 
symbol IR2=b2
symbol counter=b3


init:     
    counter=4 'start at max spaces availible
    pause 500 ; wait for display to initialise
    serout B.1,N2400,(254,1)
    pause 30



    

main:


   
'do
gosub counterbeam1
gosub counterbeam2  
   
'loop   
   
goto main




counterbeam1:

 serout B.1,N2400,(254,128)   ; move to start of first line
 serout B.1,N2400,("places availible")  ; output text   
 serout b.1, n2400, ( 254, 192 ) 'second line
 serout b.1, N2400, (#counter)
     
 readadc b.4,IR1
 debug IR1
 if IR1 <10 then goto in_the_beam  
 
goto counterbeam1
 




in_the_beam:
   readadc b.4,IR1
   debug IR1
   pause 500
   if IR1 >10 then goto out_of_the_beam
   goto in_the_beam
 

out_of_the_beam:
   let counter = counter -1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
  'return
goto main


full:
  
  debug counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2
  if IR2 <10 then goto counterbeam2

goto main 
 
 

counterbeam2:

serout B.1,N2400,(254,128)   ; move to start of first line
 serout B.1,N2400,("places availible")  ; output text   
 serout b.1, n2400, ( 254, 192 ) 'second line
 serout b.1, N2400, (#counter)
     
 readadc c.4,IR2
 debug IR2
 if IR2 <100 then goto in_the_beam2  


in_the_beam2:

readadc c.4,IR2 
   debug IR2
   pause 500
   if IR2 >100 and counter<4 then goto out_of_the_beam2
   goto in_the_beam2
 

out_of_the_beam2:
   let counter = counter +1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
goto main


this the only code i can use to make couter count down
putting return at the end of out of the beam 1 allows IR2 to be read but makes counter count back up again without IR2 being covered.


what i need to know is where i need to put return or goto main
 
Last edited by a moderator:

rossko57

Senior Member
You cannot fix your code just by putting in RETURN or GOTO

You have to structure your code differently.
At the moment, you have loops that wait for events. While the program is stuck in one of those loops, waiting for something, it will never get to the other parts of your code that act on different events. It does not make any difference if that loop-trap is in main code or a subroutine, it is still a trap.

Somehow, you have to get rid of the loops if you want your program to appear to handle more than one input at the same time.

One way to do that is to use flags. Have an indicator, a value, that your program sets so that it can keep track of where in the sequence of events it is. Look for changes at the inputs, instead of waiting for steady levels.
 

edmunds

Senior Member
I thought I could try to help as I have a few spare minutes and your challenge as far as I can understand is to count the entering and exiting cars and showing something depending on how many have entered and exited on a display. A basic code structure for this would take a couple of minutes and maybe that would get you ahead, but I could not open any of the links in your posts.

I suggest you start over by defining your project and problem. So people here can actually help. The fact that you can read an infrared beam is a notable achievement, but has little to do with ability of designing the flow of the program to deal with if and what was detected. These are almost two different arts if I can say so and you need to approach the latter with the same patience and diligence as the first one. In other words, your problem is not being able to read the second beam. Reading the second is the same as reading the first, as you, sure, understand.

Keep up the spirit, :)

Edmunds
 

hippy

Technical Support
Staff member
im really not sure where to put the return command
They need to be at the end of your subroutines and your subroutines must exit via those returns, not through a GOTO to 'main' or jumps through code which lead to a GOTO 'main'.

The best thing to do would be to write a short test program to get to understand subroutines ...

Code:
Main:
  Gosub ShowB0
  b0 = b0 + 1
  Goto Main

ShowB0:
  Debug
  [b]Return[/b]
Note that the value of b0 increments.

If you GOTO out of the subroutine then it stops working, b0 does not increment ...

Code:
Main:
  Gosub ShowB0
  b0 = b0 + 1
  Goto Main

ShowB0:
  Debug
  [b]Goto Main[/b]
 
They need to be at the end of your subroutines and your subroutines must exit via those returns, not through a GOTO to 'main' or jumps through code which lead to a GOTO 'main'.
putting return in the place of goto main made counter count back up once it went below 3

do i need to put something more in my main?
do it need to move my gosubs somewhere else?


i feel like i need to transfer more of this code over to my gosub/multitasking code


Code:
 symbol IR1=b1 
symbol IR2=b2
symbol counter=b3



init:     
    counter=4
    pause 500 ; wait for display to initialise
    serout B.1,N2400,(254,1)
    pause 30

main: 
   serout B.1,N2400,(254,128)   ; move to start of first line
   serout B.1,N2400,("places availible")  ; output text
   readadc b.4,IR1
   readadc c.4 ,IR2

debug
   
 
  if IR1 <10 then goto in_the_beam  
  if IR2 < 100 and counter <4 then goto in_the_beam2 
   
   
  serout b.1, n2400, ( 254, 192 ) 'second line
  serout b.1, N2400, (#counter)
   
   
  goto main
 

in_the_beam:
   readadc b.4,IR1
   debug 
   pause 500
   if IR1 >10 then goto out_of_the_beam
   goto in_the_beam
 

out_of_the_beam:
   let counter = counter -1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
  goto main



full:
  
  debug  counter
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  readadc c.4 ,IR2
  if IR2 <100 then goto in_the_beam2

goto  full 
 
 
in_the_beam2:

readadc c.4,IR2
   debug IR2 
   pause 500
   if IR2 >100 then goto out_of_the_beam2
   goto in_the_beam2
 

out_of_the_beam2:
   let counter = counter +1 ;the car is now out of the beam so display one less space as available (count up from 4)
   if counter=0 then goto full  'stop b1 from counting up (maximum spaces taken up)
goto main



thank-you everyone for persisting
 

hippy

Technical Support
Staff member
do i need to put something more in my main?
do it need to move my gosubs somewhere else?

i feel like i need to transfer more of this code over to my gosub/multitasking code
Possibly, but you will need to post the gosub/multitasking code you now have for anyone to be able to assess that.
 

rossko57

Senior Member
I don't know else we can say it; you are flogging a dead horse with your code as it stands. The way it is structured cannot do what you want.

Let's look at a small part

counterbeam1:
serout B.1,N2400,(254,128) ; move to start of first line
...
readadc b.4,IR1
if IR1 <10 then goto in_the_beam
goto counterbeam1

Can you see what happens when IR1 is greater than ten? The code goes round in a loop, displaying on the LCD and checking IR1 again.
While IR1 is greater than ten - which I think is the normal no-car-moving condition - your Picaxe will never, ever check what is happening with IR2.

I would suggest starting over, just using what you have learnt already in a different way.

Start simple, grow later.
You might for example leave out counting for now, and just use the two lines of LCD to display what is going on with BOTH the IR beams

pseudocode:
read IR1, decode to "clear" or "broken"
display beam 1 state on the LCD line 1
read IR2, decode to "clear" or "broken"
display beam 2 state on the LCD line 2
loop back to beginning

Once you have shown that the Picaxe can keep track of two beams at the same time, you can make it more complex

It must be frustrating, but don't give up - the Picaxe can do what you want
 

hippy

Technical Support
Staff member
I think part of the problem, titaniumnitratecoatedcow, is that you are focusing a bit too much on the "How do I do it" rather than stepping back and reflecting on "What needs to be done".

At present you are trying to knock a square peg into a round hole. While you may eventually achieve that if you hit things hard enough it's not the best way to proceed. It is understandable though, and no one intends to be critical or unkind, because starting out with programming is never easy. We have all been through it. The best anyone can learn is when stuck in a dead end, back-up and start again.

With a clear view of what you want to achieve you can design on paper a process which will achieve that. You can follow that through in your mind and check that it works, modify it as required. Then you can then turn that design into an actual program which achieves the same.

It is not necessarily an easy project either for a beginner and programs which need to do multiple things at once can always be a challenge. But if you are using an M2 then the multi-tasking capabilities of that can make things a lot simpler.

The following is how I would do a car park space counting program on an M2 PICAXE. This uses digital input pins to detect if the beam is present (1) or broken (0) and uses the Terminal to display the status rather than an LCD but may help with your own design -

Code:
#Terminal 4800

Symbol spacesLeft  = b0
Symbol spacesShown = b1

Symbol entryBeam   = pinB.4
Symbol exitBeam    = pinC.4

Symbol BROKEN      = 0

; Display routine

Start0:
  spacesLeft = 4
  Pause 500
  SerTxd( CR, LF )
  SerTxd( "Starting...", CR, LF )
  Do
    spacesShown = spacesLeft
    If spacesShown = 0 Then
      SerTxd( "Full - No spaces left", CR, LF )
    Else
      SerTxd( "Spaces Left = ", #spacesShown, CR, LF )
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    Do : Loop Until entryBeam = BROKEN
    Do : Loop While entryBeam = BROKEN
    spacesLeft = spacesLeft - 1    
  Loop

; Handle the exit beam

Start2:
  Do
    Do : Loop Until exitBeam = BROKEN
    Do : Loop While exitBeam = BROKEN
    spacesLeft = spacesLeft + 1    
  Loop
 
The following is how I would do a car park space counting program on an M2 PICAXE. This uses digital input pins to detect if the beam is present (1) or broken (0) and uses the Terminal to display the status rather than an LCD but may help with your own design -

what command do i use for the beam inputs?
 

hippy

Technical Support
Staff member
what command do i use for the beam inputs?
You can just use the 'pinX.Y' variables for digital input pins, and can put them in IF, DO-LOOP and other commands.

If reading the beam signals as analogue then you would use the READADC command as you have been doing.
 
If reading the beam signals as analogue then you would use the READADC command as you have been doing.



how do i say readadc?


Code:
; Handle the entry beam

Start1:
  Do
    readadc entryBeam
    debug
    
    
    Do : Loop Until entryBeam = BROKEN
    Do : Loop While entryBeam = BROKEN
    spacesLeft = spacesLeft - 1    
  Loop
 
was just a bit confused because i couldnt find a beam variable in hippys code.


are you suggesting i create a new variable for the beams (it only seems there are ones for the counters)
 

hippy

Technical Support
Staff member
The beam variables are 'entryBeam' (pinB.4) and 'exitBeam' (pinC.4). Because that is using digital inputs the state of the beams can be measured by simply looking at the pin level.

If using analogue inputs, the analogue inputs have to be read into additional variables and those levels compared to a value to determine if broken or not.

The code in post #21, modified to use analogue inputs, would be as follows -

Code:
#Terminal 4800

Symbol spacesLeft  = b0
Symbol spacesShown = b1

[b]Symbol entryBeam   = b2
Symbol exitBeam    = b3

Symbol ENTRY_ADC   = B.4
Symbol EXIT_ADC    = C.4

Symbol BROKEN      = 10[/b]

; Display routine

Start0:
  spacesLeft = 4
  Pause 500
  SerTxd( CR, LF )
  SerTxd( "Starting...", CR, LF )
  Do
    spacesShown = spacesLeft
    If spacesShown = 0 Then
      SerTxd( "Full - No spaces left", CR, LF )
    Else
      SerTxd( "Spaces Left = ", #spacesShown, CR, LF )
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    [b]Do : ReadAdc ENTRY_ADC, entryBeam : Loop Until entryBeam <= BROKEN
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop While entryBeam <= BROKEN[/b]
    spacesLeft = spacesLeft - 1    
  Loop

; Handle the exit beam

Start2:
  Do
    [b]Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN[/b]
    spacesLeft = spacesLeft + 1    
  Loop
 

hippy

Technical Support
Staff member
my second beam (which is working) will not have its value displayed for that code.
So update the code so that it displays the beam's value :)

The first thing to do if you are using given code is to understand how it works. If you just use given code without understanding it you will not be learning much, will not be able to move forward, and will not be able to modify for your own specific needs.

If you do not fully understand something then please do ask and indicate what parts you are having problems. People here will try to give you the information and explanation to help you as best they can.
 
i mean on the debug screen { &#865;&#8226; &#860;&#662; &#865;&#8226;}


i was planning on just getting it working on the debug screen first before adding the serout command
is it supposed to work still if i just use the debug screen?
 
Last edited:

hippy

Technical Support
Staff member
The SERTXD output is sent to the PICAXE editor Terminal display. The #TERMINAL 4800 should cause the terminal to be displayed at the correct baud rate after the program is downloaded or when simulated. If you wish to use live debugging you will have to add DEBUG commands to the code.
 
OK, so I'm using the terminal display now that i know what it is.
i think the reason why the second beam didnt work while the first did, was because the un modulated beams gave different values.

after adding the symbol broken 2 for the second beam (symbol broken2 =100), spacesleft is able to count back up. ( &#865;&#7508; &#860;&#662; &#865;&#7508; )

here is the code:


Code:
#Terminal 4800

Symbol spacesLeft  = b0
Symbol spacesShown = b1

Symbol entryBeam   = b2
Symbol exitBeam    = b3

Symbol ENTRY_ADC   = B.4
Symbol EXIT_ADC    = C.4

Symbol BROKEN      = 10
Symbol BROKEN2      = 100

; Display routine

Start0:
  spacesLeft = 4
  Pause 500
  SerTxd( CR, LF )
  SerTxd( "Starting...", CR, LF )
  Do
    spacesShown = spacesLeft
    If spacesShown = 0 Then
      SerTxd( "Full - No spaces left", CR, LF )
    Else
      SerTxd( "Spaces Left = ", #spacesShown, CR, LF )
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    
    'debug entrybeam
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop Until entryBeam <= BROKEN
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop While entryBeam <= BROKEN
    spacesLeft = spacesLeft - 1    
  Loop

; Handle the exit beam

Start2:
  Do
    
    'debug exitbeam
    Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN2
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN2
    if spacesleft <4 then spacesLeft = spacesLeft + 1    
  Loop


the problem is that nothing stops it from counting over 4, would you recommend a goto full or something else?
 
Last edited:

hippy

Technical Support
Staff member
i think the reason why the second beam didnt work while the first did, was because the un modulated beams gave different values.
No, the problem was as described earlier in the thread, but that does not matter if you are now able to read and handle both beams.

here is the code:
the problem is that nothing stops it from counting over 4, would you recommend a goto full or something else?
Your "if spacesleft <4 then spacesLeft = spacesLeft + 1" should be preventing spacesLeft going over 4.

There is nowhere else in the code that I can see where spacesLeft is incremented so it does not seem possible that spacesLeft could ever go over 4.

Double check that you actually downloaded the program after adding the "if spacesLeft < 4 then" to your program.

Also; what software are you using ? Your code does not compile in PE6.
 
i i think the problem described earlyer was that the beam wasnt being read.

''if spacesleft <4 then spacesLeft = spacesLeft + 1'' gives syntax error in pe5 and pe6

i was using pe5 but now im using pe6
 

hippy

Technical Support
Staff member
Okay; so what is the exact code which now compiles ? It will not be possible to tell what is wrong without the exact code you are using.
 
Code:
#Terminal 4800

Symbol spacesLeft  = b0
Symbol spacesShown = b1

Symbol entryBeam   = b2
Symbol exitBeam    = b3

Symbol ENTRY_ADC   = B.4
Symbol EXIT_ADC    = C.4

Symbol BROKEN      = 10
Symbol BROKEN2      = 100

; Display routine

Start0:
  spacesLeft = 4
  Pause 500
  SerTxd( CR, LF )
  SerTxd( "Starting...", CR, LF )
  Do
    spacesShown = spacesLeft
    If spacesShown = 0 Then
      SerTxd( "Full - No spaces left", CR, LF )
    Else
      SerTxd( "Spaces Left = ", #spacesShown, CR, LF )
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    
    'debug entrybeam
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop Until entryBeam <= BROKEN
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop While entryBeam <= BROKEN
    spacesLeft = spacesLeft - 1    
  Loop

; Handle the exit beam

Start2:
  Do
    
    'debug exitbeam
    Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN2
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN2
    'if spacesleft <4 then spacesLeft = spacesLeft + 1    
  Loop
 
Top