Hey everybody, I am making a remote controlled car from scratch with an ESP32 cam. I would like to control the car using either the builtin WIFI or bluetooth. Unfortunately, whiile making the code I come across an error that says "Compilation Error:a function definition is not allowed here before '{' token."
Here is my code:
// Define pins
const int echoPin = 12;
const int trigPin = 13;
// Start the sensor
DistanceSensor sensor(trigPin, echoPin);
// Motor A connections
//int enA = 9;
int in1 = 2;
int in2 = 14;
// Motor B connections
//int enB = 3;
int in3 = 15;
int in4 = 13;
void setup() {
// Start serial port
Serial.begin(115200);
// Set all the motor control pins to outputs
//pinMode(enA, OUTPUT);
//pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
void forward() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
void back() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
void left() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
void right() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
void stop() {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
server.handleClient();
command = server.arg("State");
if (command == "W") forward();
else if (command == "S") back();
else if (command == "A") left();
else if (command == "D") right();
else if (command == "E") stop();
Please help