Hello arduino people! i could use some help with some code i have written. I have built a simple arduino robot that has a simple bump switch on the front and when this is pressed it should back up and turn 90 degrees and then head forward again. i have no idea what to do with my code and i cant find any example code online. so here is my code. have a blast.
#include <Servo.h>; #include <switch.h>;
const int RForward = 0;
const int RBackward = 180;
const int LForeward = RForward;
const int LBackward = RBackward;
const int RNuetral = 90;
const int LNuetral = 90;
switch buttonPin;
Servo leftMotor;
Servo rightMotor;
No semicolons on the end of #include statements, or other preprocessor directives.
and here:
if (buttonPin == LOW);
else;
switch buttonPin;
switch is not a type.
buttonPin.attach (2);
buttonPin is not a Servo instance.
if (buttonPin == LOW);
When you get buttonPin defined correctly (const int, with a value assigned: const int buttonPin = 2;), you'll see that it is pretty obvious that 2 is not LOW.
You want, somewhere to read the STATE of the pin that the switch is attached to, and compare the state to LOW.
Anybody could, including you. What would you learn if we did it for you?
Every program goes through a stage where the compiler is barfing out errors. You need to track down each one until they are all gone. It is part of the process.
You've received a lot of good clues here. Time for some debugging. Ask specific questions and you'll get good answers.