Hi, I'm new to Arduino, and I get, error: expected unqualified-id before 'if' when I try to compile the following code:
/Program to make a robot follow a light at varying speeds based on the brightness of the light.
Uses a microcontroller, battery, two photoresistors and two servos./
int sensorpina = 14; //left
int sensorpinb = 15; //right
int servopina = 0; //left
int servopinb = 1; //rightint val = 0; //left
int bval = 0; //rightvoid setup()
{
pinMode(servopina, OUTPUT); //left
pinMode(servopinb, OUTPUT); //right
}void loop()
{
val = analogRead(sensorpina); //left
Serial.println(val); //left
val = analogRead(sensorpinb); //right
Serial.println(bval); //right
}void loop()
{
if (sensorpina < sensorpinb); //meaning the light is to the right of the robot, this is the error line
{ //turn right
digitalWrite(servopina, HIGH); //left on
digitalWrite(servopinb, LOW); //right off
}
else if (sensorpina > sensorpinb); //meaning the light is to the left of the robot
{ //turn right
digitalWrite(servopina, LOW); //left off
digitalWrite(servopinb, HIGH); //right on
}
else if (sensorpina == sensorpinb) //meaning the light is ahead of the robot
{ //go straight
analogWrite(servopina, val/4); //left
analogWrite(servopinb, bval/4); //right
}
}
I know I made several obvious mistakes, so don't tell me what I already know about how bad it is, just tell me how to fix it and really anything to make it better.