So I bought one of those robotic cars that come with a few different projects to make. One is a car that follows lines (lets call it mode 1) and another is a car that avoids obstacles (mode 2). I made both projects and learned lots about coding. I would like to combine both projects just so I dont have to reupload the code to switch between "modes".
I have an IR that can be used to switch between modes.
What would be the correct way of doing this? I think I can figure out the code if I know the correct procedure. I'm still a novice though.
Put the two things in functions, then implement a basic state machine. So you get something like this:
#define LINEFOLLOWER 0
#define OBSTACLEAVOIDANCE 1
byte mode = LINEFOLLOWER;
void loop() {
checkIR();
switch (mode) {
case LINEFOLLOWER:
linefollower();
break;
case OBSTACLEAVOIDANCE:
obstacleavoidance();
break;
}
}
void checkIR() {
// Read command over IR.
// set mode accordingly.
if (command == 'l') mode = LINEFOLLOWER;
if (command == 'o') mode = OBSTACLEAVOIDANCE;
}
void linefollower() {
// original linefollower loop()
}
void obstacleavoidance() {
// original obstacleavoidance loop()
}
Hi, Here's an example using IR to control a robot car:
http://arduino-info.wikispaces.com/RobotKitMenu-9
And some suggestions on combining sketches: