Error: expected primary-expression before '=' token

So I got about 50 of these errors when I tried to compiled my code. It seems to only occur in lines where I reference an analogRead function, eg AccelAngle=analogRead(accelerometer);

Ive attached my entire code, if it helps. A full example of the problem is as follows:

for(i=0;i<=3;i++)
{
int VoltL,VoltR;
VoltL=analogRead(LLDR);//read
VoltR=analogRead(RLDR);//read
PrintVolt(VoltL,VoltR);
MotorCon(VoltL,VoltR);
delay(100);
}

The lines with VoltL and VoltR are getting the error I mentioned. Ive no idea how to rectify this. The code is for a 3pi Pololu robot, that carries out 3 basic tasks, for context :slight_smile: :slight_smile:

Any help, recommendations would be greatly appreciated!

FINAL.ino (4.87 KB)

#define LLDR=6;

A define shouldn’t have a semicolon or an equals sign. When it gets replaced it does this…

VoltL=analogRead( =6;);

See the error now?

The define should look like:

#define LLDR 6

Thanks so much, that solved that, but now im getting an error about converting to bool?

if(motors.setSpeeds(0,0)) { buzz.playFromProgramSpace(TaskComplete); }

The first line there im getting "FINAL:67: error: could not convert 'OrangutanMotors::setSpeeds(0, 0)' to 'bool'" I never intended on this to be boolean or the sort? How can this be

tomtom412: Thanks so much, that solved that, but now im getting an error about converting to bool?

The first line there im getting "FINAL:67: error: could not convert 'OrangutanMotors::setSpeeds(0, 0)' to 'bool'" I never intended on this to be boolean or the sort? How can this be

I'd have to be able to see that library to figure it out.

What does setSpeeds return?

Because you do motors.setSpeeds(0,0) in an if statement you check it for true or false. What do you try to do and what do you expect to get from motors.setSpeeds(0,0)?

Im trying to check to see if the motors ever stop moving, to then return a sound. Should a while statement be better in that case rather than if? It gives the same error regardless.

The task is to follow the light and when it gets close to the light, the light switches off and the robot should stop moving, and play a sound to signal completion. Is there perhaps a better way of doing that?
motor.setSpeeds(10,10)
would set the left and right motors to a speed of 10, and a 0 would be a stop.

tomtom412: Im trying to check to see if the motors ever stop moving, to then return a sound. Should a while statement be better in that case rather than if? It gives the same error regardless.

The task is to follow the light and when it gets close to the light, the light switches off and the robot should stop moving, and play a sound to signal completion. Is there perhaps a better way of doing that? motor.setSpeeds(10,10) would set the left and right motors to a speed of 10, and a 0 would be a stop.

It isn't a matter of while vs. if. They both take the same kind of conditionals.

The question is what does setSpeeds return. Does it return a value at all? If not then you can't use it in an if statement. Or a while.

Ah I see. Thanks

I’m not sure I’m finding the exact same version of the library that you are using, but it appears that setSpeed returns void. That means it returns nothing.

You might as well write:

if(){
     buzz.playFromProgramSpace(TaskComplete);
}

It’s not going to work. It’s going to give an error.

Dont suppose you'd have any idea on how to monitor the motor activity so that if they came to a stop, a sound is played? haha any help at all would be immensely appreciated

tomtom412: Dont suppose you'd have any idea on how to monitor the motor activity so that if they came to a stop, a sound is played? haha any help at all would be immensely appreciated

How are you getting feedback from the motors? Have you got a sensor or something there to know if they are turning or not?

No ive no sensor to know if theyre turning or not. Im very much a beginner at this so im just running off the functions that ive come across from the respective libraries. Actually, im aware of how to monitor how long theyve been running, but thats far too messy for the task, and would need there to be no error in the final testing

tomtom412: No ive no sensor to know if theyre turning or not. Im very much a beginner at this so im just running off the functions that ive come across from the respective libraries. Actually, im aware of how to monitor how long theyve been running, but thats far too messy for the task, and would need there to be no error in the final testing

If there's no sensor to tell if the motors are running, then what are you expecting to test in that if? Whether or not the command was sent? You wrote the line to send it, so I think you can rest assured it got sent.