Hi! Wonder if anyone could help me out here with this code because I keep getting several problems. Whenever I try to upload my code, I get an error message saying 'exit status 1 expected unqualified-id before 'if''
Here's my code:
int val = 0;
void setup()
{
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
}
if(analogRead(A0) > 500) // This is the Left Sensor
{
digitalWrite(8,LOW); // Stops the Right motor from moving
digitalWrite(9,LOW);
}
else
{
digitalWrite(9,HIGH); // Makes the Right motor move foward
digitalWrite(8,LOW);
end
}
if(analogRead(A3) > 500) // This is the Right Sensor
{
digitalWrite(13,LOW); // Stops the Left Motor from moving
digitalWrite(12,LOW);
}
else
{
digitalWrite(13,HIGH); // This makes the Left motor move foward.
digitalWrite(12,LOW);
}
Serial.println(val); // Prints the Sensor Value
}
int val = 0;
void setup()
{
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
} //DELETE THIS - this closes the loop() function, so all the code after it is not in a function, which is not valid
if(analogRead(A0) > 500) // This is the Left Sensor
{
digitalWrite(8,LOW); // Stops the Right motor from moving
digitalWrite(9,LOW);
}
else
{
digitalWrite(9,HIGH); // Makes the Right motor move foward
digitalWrite(8,LOW);
end
}
if(analogRead(A3) > 500) // This is the Right Sensor
{
digitalWrite(13,LOW); // Stops the Left Motor from moving
digitalWrite(12,LOW);
}
else
{
digitalWrite(13,HIGH); // This makes the Left motor move foward.
digitalWrite(12,LOW);
}
Serial.println(val); // Prints the Sensor Value
}
Thanks for that it worked but the second part of the analogRead is still having troubles. Im doing the same way you told me to do it but now the '}' is having problems at the end, I delete the last last one. I delete it and it says it has problems. I put it back. It says "expected '}' at end of input" and if I delete it this is what it says the same thing.
Ok so a friend helped me out and the code works now!
But there is one problem. The wheels wont move and if I try printing the serial so I can see, it's stuck at the number '243' and it wont go up or down.
But the main problem is the sensors work but the wheels don't move one pixel.