@GAP,
The
++b4 seemingly come form the
C programming language rather than PICAXE BASIC. Within C this is the increment function/operator.
As others have indicated this needs to be changed to
inc b4
Another part of the program where there is a bad construct is:
Code:
if
:
:
:
else if
GoTo start
end if
GoTo Start
The line with "else if" alone will not work as the
else parameter is expecting a test/comparison as the basis for the next line(s).
Sine the "else if" only leads to "Goto Start" on the subsequent line and following the "end if" line there is also "Goto Start" ,
the part
can be deleted.
Below is a "new" version of your code with:
1. Some further syntax corrections (for example "count" is a PICAXE command and cannot be used as a variable name - changed here to "countr")
2. nested lines indented which make the groups of lines in each nest level easier to identify.
Indenting the lines AND adding more comments to indicate the purpose of the program lines together with a few header lines describing the program purpose are the key to good documentation.
Code:
symbol left=b0
symbol right=b1
SYMBOL countr = b2
SYMBOL servopin = b.4
start:
Low B.1 ;Set B.1 as an output and low
Low B.2 ;Set B.2 as an output and low
b5 = 0 ;this is to keep track of the state of the lights
readadc c.4,left ;read adc into variable b0
readadc c.0,right ;read adc into variable b1
readadc c.4,left ;looks at both inputs
readadc c.0,right
if left>128 then ;if left is greater than 128 then flash lights
GoSub ChangeLights
GoSub BoomDown
GoSub ChangeLights
do
readadc c.0,right
If b4 =5 Then
GoSub ChangeLights
b4 = 0
endif
inc b4
loop while right<128
do
readadc c.0,right
If b4 =5 Then
GoSub ChangeLights
b4 = 0
endif
inc b4
loop while right>128
end if
if right>128 then
do
readadc c.4,left
If b4 =5 Then
GoSub ChangeLights
b4 = 0
endif
inc b4
loop while left<128
do
readadc c.4,left
If b4 =5 Then
GoSub ChangeLights
b4 = 0
endif
inc b4
loop while left>128
GoSub ChangeLights
GoSub BoomUp
end if
GoTo Start
ChangeLights: ;this sets which light is on/off based on the value of the b5 variable and then XORs (flips it between 1 and 0) it so that next time the sub is called it switches them back.
if b5 = 0 then
low B.1
high B.2
else
high B.1
low B.2
endif
b5 = b5 XOR 1
Return
BoomUp:
for countr = 75 to 225
servo servopin,countr
pause 1
next countr
Return
BoomDown:
for countr = 225 to 75 step -1
servo servopin,countr
pause 1
next countr
Return