Syntax error

mirko5

New member
I am using the 14m2 with 3 ultrasonic sensors and I get this message while trying to run the code:

symbol pingDistance1, pingDistance2, pingDistance3
^
Syntax error on line 7 at/before position 21

Error: syntax error


Here is my code that I am using:

symbol PING_1 = PIN0
symbol PING_2 = PIN1
symbol PING_3 = PIN2
symbol MOTOR_A = PIN6
symbol MOTOR_B = PIN7

symbol pingDistance1, pingDistance2, pingDistance3

symbol DISTANCE_THRESHOLD = 2

symbol ALL_SENSORS_PICKING_UP_OBJECT = 1;

; Main loop
Do: Loop
' Read the ultrasonic sensors
;pingDistance1 = ping(PING_1)
;pingDistance2 = ping(PING_2)
;pingDistance3 = ping(PING_3)

' Check if all sensors are picking up a signal with a distance of >2cm
if pingDistance1 > DISTANCE_THRESHOLD && pingDistance2 > DISTANCE_THRESHOLD && pingDistance3 > DISTANCE_THRESHOLD then
' Set the flag
;ALL_SENSORS_PICKING_UP_OBJECT = 1;

else
' Clear the flag
;ALL_SENSORS_PICKING_UP_OBJECT = 0;

endif

' If all sensors are picking up a signal with a distance of >2cm, run the motors forward
if ;ALL_SENSORS_PICKING_UP_OBJECT then
' Set the motor pins
output MOTOR_A = 1
output MOTOR_B = 1

' Wait for the time to run the motors forward
pause 10000

' Stop the motors
output MOTOR_A = 0
output MOTOR_B = 0

else
' If at least 1 sensor stops picking up a signal with a distance of >2cm, run the motors back
' Set the motor pins
output MOTOR_A = 0
output MOTOR_B = 1

' Wait for the time to run the motors back
pause 10000

' Stop the motors
output MOTOR_A = 0
output MOTOR_B = 0

' Exit the loop
Exit Loop
endif
End Do

If anyone could help me with this it would be very appreciated!
 

papaof2

Senior Member
I suspect you can't define more than one symbol per line but would need to bring up the PICAXE manual to verify that.
 

mirko5

New member
Thanks that fixed it.
However, I am now getting a syntax error here:

if ;pingDistance1 > DISTANCE_THRESHOLD && ;pingDistance2 > DISTANCE_THRESHOLD && ;pingDistance3 > DISTANCE_THRESHOLD then
^
Syntax error on line 23 at/before position 122

Error: syntax error
 

mirko5

New member
Thanks. Getting another syntax error here though, unsure how to fix

if ALL_SENSORS_PICKING_UP_OBJECT = 1 then
^
Syntax error on line 34 at/before position 32

Error: syntax error
 

The bear

Senior Member
Hi,
Just a guess; if, needs an endif.
You shouldn't be inserting " ; " ,unless you want comment the line/code out. ( As papaof 2 said).
Good luck..............
 

cpedw

Senior Member
Your lines
symbol DISTANCE_THRESHOLD = 2

symbol ALL_SENSORS_PICKING_UP_OBJECT = 1
defin the names DISTANCE_THRESHOLD and ALL_SENSORS_PICKING_UP_OBJECT as constants that have the values 2 and1 throughout the program.
Putting a ; in makes the line a comment.
To set the name as a variable, use something like
symbol DISTANCE_THRESHOLD = b0
symbol ALL_SENSORS_PICKING_UP_OBJECT = b1

Your use of output doesn't match the picaxe command. I suspect (but only you know what you're trying to do) you want something like
MOTORA=0,
having defined
symbol MOTORA=b.1
but using the appropriate pin label for your setup.
 

hippy

Technical Support
Staff member
Code:
symbol ALL_SENSORS_PICKING_UP_OBJECT = 1
if ALL_SENSORS_PICKING_UP_OBJECT = 1 then
That gives a syntax error because a limitation of PICAXE is that you cannot have a numeric constant on the left-hand side of the comparison, it must be a variable.

Given that you also wish to do 'ALL_SENSORS_PICKING_UP_OBJECT = 0' and '= 1' it looks like 'ALL_SENSORS_PICKING_UP_OBJECT ' should have been defined as a variable in the SYMBOL definitions rather than as a named constant whose value cannot be changed, as 'cpedw' showed.

The solution here is to define 'ALL_SENSORS_PICKING_UP_OBJECT ' as a variable, but, if it is necessary to test the value of a constant that can be done by moving the constant into a variable and testing that, for example -
Code:
Symbol RED   = 0
Symbol GREEN = 1
Symbol LED   = GREEN

b0 = LED
If b0 = RED Then
  Gosub FlashRedLed
Else
  Gosub FlashGreenLed
End If
 
Top