0
hello.. I am beginner and am developing an altonomic cart and found an error in the compilation
Arduino: 1.8.13 (Linux), Card:"Arduino Uno"
/home/Acer/snap/Arduino/Current/Arduino/cart_autonomo1.0/cart_autonomo1.0.In: In Function 'void loop()': cart_autonomo1.0:54:9: error: 'Else' without a Previous 'if' Else (distance < 500){ ~~ cart_autonomo1.0:54:15: error: 'distacia' was not declared in this Scope Else (distance < 500){ ~~~~~~~~~ /home/Acer/snap/Arduino/Current/Arduino/cart_autonomo1.0/cart_autonomo1.0.Ino:54:15: note: suggested Alternative: 'distance' Else (distance < 500){ ~~~~~~~~~ distance cart_autonomo1.0:66:9: error: 'Else' without a Previous 'if' Else (action != "left"){ ~~ cart_autonomo1.0:66:34: error: expected ';' before '{' token Else (action != "left"){ ^ cart_autonomo1.0:73:11: error: 'Else' without a Previous 'if' Else (action == "left"){ ~~ cart_autonomo1.0:73:36: error: expected ';' before '{' token Else (action == "left"){ ^ cart_autonomo1.0:79:11: error: break statement not Within loop or switch break ~~~ cart_autonomo1.0:80:5: error: expected ';' before '}' token } ^ Exit status 1 'Else' without a Previous 'if'
that’s the mistake.
follows the code /second program18/11/
#include<Ultrasonic. h>
//sets the ultrasonic pins
#defines triger 12 #define echo 13
// sets rear engine control pins #define pmt1 3 #define pmt2 5
//sets direction pins to vehicle
#define pdir 0 #defines pesq 1
//initializes ultrasonic sensor Ultrasonic Ultrasonic(triger, echo);
int speed =0; String action;
void setup() { // starts serial monitor Serial.Begin(9600); pinMode (pmt1, OUTPUT); pinMode (pmt2, OUTPUT); pinMode (pdir, OUTPUT); pinMode (pesq, OUTPUT); //char acao; }
void loop() { //make distance reading int distance;
distance = Ultrasonic.read(); Serial.print ("distance in cm:"); Serial.println (distance); delay(1000);
//determines speed //int speed; if (distance>1000){ // speed = 192; Serial.println("speed selected 75% of rpm"); } Else (distance < 1000 and distance > 500);{ speed = 128; Serial.println("speed selected 50% of rpm"); } Else (distance < 500){ speed = 64; Serial.println("speed selected 25% of rpm"); }
//action analysis (front, right, left, or re
//char acao; String action;
if (distancia<200);{
//vira pra direita
else (acao != "esquerda"){
digitalWrite(pdir,HIGH);
digitalWrite(pesq,LOW);
acao="esquerda";
//FALTA SUB PARA TRACIONAR MOTOR
}
//vira pra esquerda
else (acao == "esquerda"){
digitalWrite(pdir,LOW);
digitalWrite(pesq,HIGH);
acao="direita";
//falta sub para tracionar motor
}
break
}
}
thank you
That your first one should be an if.
– Mr. Satan