my second infra red beam wont give a value

hi all, after getting my infra red beam code working (see hereView attachment 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/d/1T1K_aDjZbb79kVpbd1TgWlw0I-pKqUERB4Gvew98sAQ/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   
   





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
goto main




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)
  'goto main
  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 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 <100 then goto in_the_beam2  
goto counterbeam2




in_the_beam2:

readadc c.4,IR2 
   debug IR2
   pause 500
   if IR2 >100 and counter<4 then goto out_of_the_beam2
   'goto main
 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:

inglewoodpete

Senior Member
I don't understand what you're trying to do. Why are you using ReadADC to read different IR inputs? An IR receiver should give a digital output: 0 or 1. If you use ADC to determine if an IR beam is present or not, you will be picking up all sorts of weird readings, depending on the ambient temperature, lighting levels and the temperature of objects and/or reflected heat from all sorts of sources.

An infrared source needs to be a modulated (Eg 38 kHz) IR beam, usually one or more LEDs pulsing together.
 
I don't understand what you're trying to do. Why are you using ReadADC to read different IR inputs? An IR receiver should give a digital output: 0 or 1. If you use ADC to determine if an IR beam is present or not, you will be picking up all sorts of weird readings, depending on the ambient temperature, lighting levels and the temperature of objects and/or reflected heat from all sorts of sources.

An infrared source needs to be a modulated (Eg 38 kHz) IR beam, usually one or more LEDs pulsing together.

i dont have enough pins to use a modulated pwmout command.
my last code structure worked without doing this by just changing the goto values accordingly.
 
Top