Hello all!
Like many others, I am new to this. I am trying to bring an idea to fruition that I had back in 1999, a automated lawn mowing robot. I know they now have them available to purchase, even build kits with code and all the parts, but doing it this way also will help me learn coding/programming, which is something I am deficient in. After procuring parts and writing a basic sketch to check motor and motor driver funtionality, I started writing in parts to use a Left and Right "NO" switch. My intention is for it to default run in forward, if it receives an input from bumpLeft, bumpRight, or both it executes the listed routine. After spending the last 3 days fiddling with it and the ensuing errors etc, and googling looking for trouble shooting with my sketch, I have deleted the both bumper parts to simplify.
I am using an AtMega2560, I have since unplugged board from my prototype robot and built a circuit on a breadboard with LED's to represent "motor run conditions"-Forward, backwards, right bump, left bump.
I am currently getting an error after changing this sketch so many times thus far,
" exit status 1
a function-definition is not allowed here before '{' token "
// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections
int enB = 3;
int in3 = 4;
int in4 = 5;
// Bumper switches
const int bumpLeft = 26; //Left bumper pin D26
const int bumpRight = 27; //Right bumper pin D27
int pbLeft = LOW; //Var for left bumper
int pbRight = LOW; //Var for right bumper
// Turn indicator
int turnLeft = 48; //Turn Left
int turnRight = 49; //Turn Right
void setup() {
// Set all motor control pins to outputs
pinMode(26, INPUT);
pinMode(27, INPUT);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(48, OUTPUT);
pinMode(49, OUTPUT);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
int Forward(); //Start forward
// Test bumper switches
pbLeft = digitalRead(26);
pbRight = digitalRead(27);
// If right bumper hit
if (digitalRead(27) != LOW) {
int Stop();
delay(1000);
int Reverse();
delay(1000);
int turnRight();
delay(500);
// If left bumper hit
if (digitalRead(26) != LOW) {
int Stop();
delay(1000);
int Reverse();
delay(1000);
int turnLeft();
delay(500);
}
// Forward
else {
int Forward();
}
}
void Forward() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
void Reverse() {
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 turnLeft() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
digitalWrite(48, HIGH);
}
void turnRight() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
digitalWrite(49, HIGH);
}
I am not even sure if I am able to get a loop type "condition scan"
My background is Industrial Maintenance, and it has not been easy to stop thinking in terms of a logic(PLC) program where there is a constant ongoing scan.
Thank you in advance for any insight.
sketch_bumper_test_breadboard_v1.0.ino (2.26 KB)