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

hippy

Technical Support
Staff member
Okay; let's not let things get out of hand.

@ titaniumnitratecoatedcow ...

What grim_reaper is saying is that you have to uncomment the line for it to have any effect. Of course, when you do you get a syntax error.

Because, as Texasclodhopper points out, you have to use an END IF in your code to get it to compile without a syntax error.

You probably want the code to be as follows -

Code:
If spacesleft < 4 Then
  spacesLeft = spacesLeft + 1    
End If
An alternative would be -

Code:
spacesLeft = spacesLeft + 1 Max 4
 
this happens when i hold my hand in the beam

picaxe terminal display.PNG

Capture.PNGcode:


it appears on the debug screen that hte values only change if both beams a re covered at the same time. or mabe i just put the debug command in the wrong place


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      = 50

; 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 : 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
    Do : ReadAdc EXIT_ADC, exitBeam : Loop Until exitBeam <= BROKEN
    Do : ReadAdc EXIT_ADC, exitBeam : Loop While exitBeam <= BROKEN
    spacesLeft = spacesLeft + 1    
  Loop
 
Last edited:
Top