model parking garage help

i am halfway through making a model parking garage for a school. here is a basic diagram of what it does
View attachment 18687


View attachment 18688


after completing the individual subsystems i have run intp some trouble with adding the fist barrier arm subsystem to the main code. ( when added,the servo arm moves more tan it did on its own)
is

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

; Display routine

Start0:
  serout B.1,N2400,(254,1)
    pause 30
  
  
  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 )
      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, (#spacesshown)
    
    
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop Until entryBeam <= BROKEN
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop While entryBeam <= BROKEN
    spacesLeft = spacesLeft - 1 
  
  if spacesleft = 0 then 
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  elseif spacesleft > 0 then goto Start1
  
  
 End If
    'Do : Loop Until spacesShown <> spacesLeft
  
  Loop

; Handle the exit beam

Start2:
  Do
    Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN
       
    spacesLeft = spacesLeft + 1 Max 4
  
  Loop



start3:

servo b.3, 80 ;set the initial servo position @  position 137

arm1:

irin b.2,b0
debug

if b0>=20 then up
if b0<20 then down
goto arm1

up:
servopos b.3, 180 ;change the servos position without reseting the timer
pause 500
goto arm1

down:
servopos b.3,80
pause 500
goto arm1
 

rossko57

Senior Member
Code:
...
Symbol spacesLeft  = b0
...



start3:
...
irin b.2,b0
If you allocate a variable for one purpose (counting spaces) it is really unwise to allow some other routine to alter it for a completely different purpose (reading beams)

As variable b0 is generally useful for all sorts of odd jobs, it is probably a good idea to leave that as an unallocated working space (for things like reading beams) and to redesignate your spaces counter to some other variable.
 

hippy

Ex-Staff (retired)
By "moves more" do you mean moves more frequently or moves a greater distance when opened / closed ?
 
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

; Display routine

Start0:
  serout B.1,N2400,(254,1)
    pause 30
  
  
  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 )
      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, (#spacesshown)
    
    
    End If
    Do : Loop Until spacesShown <> spacesLeft
  Loop

; Handle the entry beam

Start1:
  Do
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop Until entryBeam <= BROKEN
    Do : ReadAdc ENTRY_ADC, entryBeam : Loop While entryBeam <= BROKEN
    spacesLeft = spacesLeft - 1 
  
  if spacesleft = 0 then 
  serout B.1,N2400,(254,1)
  serout b.1, n2400, ( 254, 128 ) 'second line
  serout b.1, n2400, ( "park is full " )
  elseif spacesleft > 0 then goto Start1
  
  
 End If
    'Do : Loop Until spacesShown <> spacesLeft
  
  Loop

; Handle the exit beam

Start2:
  Do
    Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN
       
    spacesLeft = spacesLeft + 1 Max 4
  
  Loop



start3:

servo b.3, 80 ;set the initial servo position @  position 137

arm1:

irin b.2,b4
debug

if b4>=20 then up
if b4<20 then down
goto arm1

up:
servopos b.3, 180 ;change the servos position without reseting the timer
pause 500
goto arm1

down:
servopos b.3,80
pause 500
goto arm1
 
Top