infra red beam not making b1 count up

I am making a model parking garage which involves cars passing through an infra red beam.
the amount of cars that pass through the beam makes variable b1 count up, the value of b1 is then displayed on an lcd screen.

the problem is i want b1 to only count up once the cars have exited the beam.

this is how i have tried to solve this but now it wont make b1 count up at all :confused::D any help would be much appreciated.

Code:
#no_data 

#com 3


init:     

    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 taken") ; output text


'for b0 = 1 to 10
irout b.2, 1, 16 ; Send the command 
pause 45    ; Pause after each command sent 
'next b0
'pause 1000    ; Wait 10 seconds 

readadc b.3,b1
debug
if b1 <50 then goto in_the_beam'the car needs to be in the beam, but the exit the beam for b2 to count down, 
'otherwise a car could sit in the beam for too long and cause multiple spaces to be displayed as taken.
'if b1 >50 then 
goto main
 


in_the_beam:
pause 500
if b1 >50 then goto out_of_the_beam





out_of_the_beam:
pause 200
 let b2 = b2 +1 ;the car is now out of the beam so display one less space as availible (count down from 4)
if b1 < 50 then goto in_the_beam
 
 if b2 =4 then goto four
 if b2 =3 then goto three
 if b2 =2 then goto two
 if b2 =1 then goto one
 if b2>4 then goto full  'stop b1 from counting up (maximum spaces taken up)
goto main



one:

serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( b1, "1" )  'display one
goto main


two:
serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( b1, "2" )  'display 2 
goto main

three:
serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( b1, "3" )  'display 3
goto main

four:
serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( b1, "4" )  'display 4 
goto main

full:

let b2=b2 'stop at 0
'serout b.1, n2400, ( 254, 128 ) 'second line
'serout b.1, n2400, ( b1, "the park is full " )
 
Last edited by a moderator:

Technical

Technical Support
Staff member
Have a think about the in_the_beam section. What happens if b1 < 50 and b1 > 50 (clue: its the same, and b1 is never changing from the original value here either.)
 
will this help with
'What happens if b1 < 50 and b1 > 50'

in_the_beam:
pause 500
if b1 >50 then goto out_of_the_beam
goto in_the_beam


the debugging stops once the beam is covered, what is causing 'b1 to never change from the original value?
 

techElder

Well-known member
You haven't told us what "readadc b.3,b1" is reading. We don't have the project in front of us, and you haven't furnished a schematic.

Generally speaking, if you want to count something large, you will have to have at least 2 "beams" for it to break. With 2 beams, you will also be able to determine what DIRECTION the object is moving, too.

If the object is going in, it will break the first beam and then the second beam. If it is going out, it will do the reverse.

You count the object if it has broken both beams in sequence, but you place the 2 beams so that both of them will be broken together at some point. That way you don't count humans or dogs coming into and out of your garage.
 
"readadc b.3,b1 is refering to the infrared beam receiver.
i am only working on the entrance IR beam right now, when i do put the exit beam in, it will count down the spaces taken
 

Technical

Technical Support
Staff member
will this help with
'What happens if b1 < 50 and b1 > 50'

in_the_beam:
pause 500
if b1 >50 then goto out_of_the_beam
goto in_the_beam


the debugging stops once the beam is covered, what is causing 'b1 to never change from the original value?
Yes that helps. But now when b1 is < 50 you are stuck going around this loop forever . How is b1 ever going to change when you are within this loop?

So you need a readadc within this loop as well, so that b1 is updated with the new values.
Keep going, you are nearly there!
 
once that suggestion had been implemented and other changes made my code now does what i wanted it to do.
thank you so much for your advice.



here is the new code

#no_data

#com 3


init:
b2=0
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 taken") ; output text
irout b.2, 1, 16 ; Send the command
pause 45 ; Pause after each command sent



readadc b.3,b1
debug
if b1 <50 then goto in_the_beam'the car needs to be in the beam, but the exit the beam for b2 to count down,
'otherwise a car could sit in the beam for too long and cause multiple spaces to be displayed as taken.
'if b1 >50 then
goto main



in_the_beam:

readadc b.3,b1
pause 500
if b1 >50 then goto out_of_the_beam
goto in_the_beam





out_of_the_beam:

let b2 = b2 +1 ;the car is now out of the beam so display one less space as availible (count up from 4)
if b1 < 50 then goto in_the_beam

if b2 =4 then goto four
if b2 =3 then goto three
if b2 =2 then goto two
if b2 =1 then goto one
if b2>4 then goto full 'stop b1 from counting up (maximum spaces taken up)

goto main



one:

serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( "1" ) 'display one
goto main


two:
serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( "2" ) 'display 2

goto main

three:
serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( "3" ) 'display 3

goto main

four:
serout b.1, n2400, ( 254, 192 ) 'second line
serout b.1, n2400, ( "4" ) 'display 4

goto main

full:

let b2=b2 'stop at 0
'serout b.1, n2400, ( 254, 128 ) 'second line
'serout b.1, n2400, ( b1, "the park is full " )
 
Top