Hi,
Im working on this project. I need to submit it very soon. I wrote the code but Im getting this error msg.
Error Msg: AUBO:122: error: expected unqualified-id before 'else'
else if ( distance > 20 || slow = 1 )
^
AUBO:126: error: expected unqualified-id before 'else'
else if ( distance < 20 || norm = 1 )
^
AUBO:131: error: expected unqualified-id before 'else'
else if ( distance > 20 || norm = 1 )
^
AUBO:135: error: expected declaration before '}' token
}
^
exit status 1
expected unqualified-id before 'if'
Then here's the code -
// AUBO v0.3
// by Vedaant Yadav
const int UTrig = 3;
const int UEcho = 2;
const int motorA1 = 5;
const int motorA2 = 6;
const int motorB1 = 9;
const int motorB2 = 10;
int duration = 0;
int distance = 0;
int start = 0;
int slow = 0;
int norm = 0;
int state = 'S';
int vSpeed = 100;
void setup()
{
pinMode(UTrig , OUTPUT);
pinMode(UEcho , INPUT);
pinMode(motorA1 , OUTPUT);
pinMode(motorA2 , OUTPUT);
pinMode(motorB1 , OUTPUT);
pinMode(motorB2 , OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (start == 0) {
delay (10000);
if (distance < 5) {
int norm = 1;
}
else if (distance > 5) {
int slow = 1;
}
}
}
if (norm == 1) {
int vSpeed = 230;
}
else if (slow == 1) {
int vSpeed = 80;
}
/Forward*****/
//If state is equal with letter 'F', car will go forward!
if (state == 'F') {
analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); analogWrite(motorB2, 0);
}
/Forward Left**/
//If state is equal with letter 'G', car will go forward left
else if (state == 'FL') {
analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
analogWrite(motorB1, 200); analogWrite(motorB2, 0);
}
/Forward Right**/
//If state is equal with letter 'I', car will go forward right
else if (state == 'FR') {
analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); analogWrite(motorB2, 200);
}
/Backward*****/
//If state is equal with letter 'B', car will go backward
else if (state == 'B') {
analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed);
analogWrite(motorB1, 0); analogWrite(motorB2, 0);
}
/Backward Left**/
//If state is equal with letter 'H', car will go backward left
else if (state == 'BL') {
analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed);
analogWrite(motorB1, 200); analogWrite(motorB2, 0);
}
/Backward Right**/
//If state is equal with letter 'J', car will go backward right
else if (state == 'BR') {
analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed);
analogWrite(motorB1, 0); analogWrite(motorB2, 200);
}
/Left**/
//If state is equal with letter 'L', wheels will turn left
else if (state == 'L') {
analogWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 200); analogWrite(motorB2, 0);
}
/Right**/
//If state is equal with letter 'R', wheels will turn right
else if (state == 'R') {
analogWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); analogWrite(motorB2, 200);
}
/Stop*****/
//If state is equal with letter 'S', stop the car
else if (state == 'S'){
analogWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); analogWrite(motorB2, 0);
}
digitalWrite(UTrig , HIGH);
delayMicroseconds(1000);
digitalWrite(UTrig , LOW);
duration = pulseIn(UEcho , HIGH);
distance = (duration/2) / 28.5 ;
Serial.println(distance);
if ( distance < 20) ||slow = 1)
{
int state = 'L'
delay(100);
}
else if ( distance > 20 || slow = 1 )
{
int state = 'F'
}
else if ( distance < 20 || norm = 1 )
{
int state = 'L'
delay(100);
}
else if ( distance > 20 || norm = 1 )
{
int state = 'F'
}
}
Please its urgent. Any help is apprecited.
Thanks,
Vedaant