Hi everyone.
Im new into this arduino programing and i totaly love it!
Im building a realy simple 3 servo hexapod walker. All the building is completed and im able to program it to do different thing for example walk forward, or turn.
But the thing is that i want to build so i can control it with a wired control. For example, when i push "the forward button" on my little wired control, the arduino is supposed run the written "forward loop" to make all the servos do what i have programed them for. And when i push the turn right button, its supposed to run the "turn right" loop.
So i need some help with a script where i can have more then one loop, and each of them are not supposed to run until its button i pushed.
I also need help with where to connect the buttons on the board and how to make the arduino read them. Just simple push and release buttons.
I dont need any superfancy scripts, just something to make it work. But if its not to hard to write, it would be awsome if the loop would stop when the button is released. It gives a bit more control. But thats not necesary. Its my first bot right :P I only need this to work for 4 buttons to begin with.
Here is the "base" script that im using to set up a single loop to make the robot do something. I dont need the whole script to be written here, i just need an example of a 2-button-2-loop script and i will probably understand the deal and be able to add more loops myself. It would be great if the new script could be built around this one so i can recognize some parts of it. Makes it alot easier to understand.
Thanks for a great forum!
#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
void setup() {
servoLeft.attach(13); // Set left servo to digital pin 13
servoRight.attach(12); // Set right servo to digital pin 12
// This is an early script, thats why the 3rd servo isnt added yet
}
void loop() { // I want to have more loops.And they are supposed to starts when i push a defined button for example "forward loop"
stopRobot(); // What routine to run
delay(4000); // How long it runs that routine
turnLeft();
delay(6000);
forward();
delay(2000);
reverse();
delay(2000);
}
// Motion routines for forward, reverse, turns, and stop. The motion routines dont need any modifications to do this? Am i right?
// I want to use the same routines but in different orders in the different loops
void reverse() {
servoLeft.write(0);
servoRight.write(180);
}
void forward() {
servoLeft.write(180);
servoRight.write(0);
}
void turnRight() {
servoLeft.write(0);
servoRight.write(80);
}
void turnLeft() {
servoLeft.write(180);
servoRight.write(79);
}
void stopRobot() {
servoLeft.write(80);
servoRight.write(80);
}