I have several problems, but dont know how to solve. please help me
error
motor_control:120:7: error: expected ';' before 'break'
break;
^~~~~
motor_control:136:18: error: 'distance' was not declared in this scope
Serial.println(distance);
^~~~~~~~
C:\Users\CHOLAB\Desktop\motor_control\motor_control.ino:136:18: note: suggested alternative: 'isSpace'
Serial.println(distance);
^~~~~~~~
isSpace
exit status 1
expected ';' before 'break'
Here is code
#define echo 2
#define trig 3
//Define pin numbers
//right motor
int m1f = 11;
int m1f_in1 = 12;
int m1f_in2 = 13;
//left motor
int m2f = 6;
int m2f_in1 = 7;
int m2f_in2 = 5;
char value;
int val[3];
int len;
int direc;
void setup()
{
//start serial communication at Baud rate of 9600
Serial.begin(9600);
pinMode(m1f, OUTPUT);
pinMode(m2f, OUTPUT);
pinMode(m1f_in1, OUTPUT);
pinMode(m1f_in2, OUTPUT);
pinMode(m2f_in1, OUTPUT);
pinMode(m2f_in2, OUTPUT);
pinMode(trig, OUTPUT); // trig 출력 설정
pinMode(echo, INPUT); // echo 입력 설정
}
void execute()
{
int no;
int i = 0;
float distance, duration;
duration = pulseIn(echo, HIGH);
distance = ((float)(340*duration) / 10000) / 2;
//convert ASCII value from serial buffer into int
no = value - '0';
//Serial.println(no);
int a, c;
/*
"""
Direction control Index:
'<' , '>' are the frame check bits for serial communication
Numbers represent the direction to be moved as per their position on numpad
4: Left
5: Stay still
6: Right
7: Front Left
8: Forward
9: Forward right
"""
*/
switch (no)
{
case 4:
a = 255; c = 255;
digitalWrite(m1f_in1, HIGH);
digitalWrite(m1f_in2, LOW);
digitalWrite(m2f_in1, LOW);
digitalWrite(m2f_in2, HIGH);
break;
case 5:
a = 0; c = 0;
digitalWrite(m1f_in1, HIGH);
digitalWrite(m1f_in2, HIGH);
digitalWrite(m2f_in1, HIGH);
digitalWrite(m2f_in2, HIGH);
break;
case 6:
a = 255; c = 255;
digitalWrite(m1f_in1, LOW);
digitalWrite(m1f_in2, HIGH);
digitalWrite(m2f_in1, HIGH);
digitalWrite(m2f_in2, LOW);
break;
case 7:
a = 255; c = 100;
digitalWrite(m1f_in1, HIGH);
digitalWrite(m1f_in2, LOW);
digitalWrite(m2f_in1, HIGH);
digitalWrite(m2f_in2, LOW);
break;
case 8:{
if(distance >= 200)
{
a = 150; c = 150;
digitalWrite(m1f_in1, HIGH);
digitalWrite(m1f_in2, LOW);
digitalWrite(m2f_in1, HIGH);
digitalWrite(m2f_in2, LOW);
}
else{
a = 0; c = 0;
digitalWrite(m1f_in1, HIGH);
digitalWrite(m1f_in2, HIGH);
digitalWrite(m2f_in1, HIGH);
digitalWrite(m2f_in2, HIGH);
}
break;
}
case 9:
a = 100; c = 255;
digitalWrite(m1f_in1, HIGH);
digitalWrite(m1f_in2, LOW);
digitalWrite(m2f_in1, HIGH);
digitalWrite(m2f_in2, LOW); 1
break;
}
analogWrite(m1f, a);
analogWrite(m2f, c);
//delay(255);
}
void loop()
{
digitalWrite(trig, HIGH);
delay(10);
digitalWrite(trig, LOW);
Serial.println(distance);
if (Serial.available())
{
//Check for frame control bits
char ch = Serial.read();
if (ch == '<')
{
len = 0;
}
else if (ch == '>')
{
execute();
//Serial.println(value);
len = 1;
}
else if (len == 0)
value = ch;
}
}
In the first error, there is semi-colon, but the error happened again, so I dont know how to solve