Hi,
I am building a robot with two servo motors and I have the circuit built for the servo motors and a pushbutton to start and stop the servos. I am finding it hard to do any correct code for the pushbutton. The code for the servos are working perfectly. If someone could help me with my code and add pushbutton code to the code below it would be very appreciated!
(servo motor code)
// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo1; // a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int pos1 = 0;
int negpos = 0;
void setup()
{
myservo.attach(11); // attaches the servo on pin 9 to the servo object
myservo1.attach(3);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 179 degrees - anticlockwise
{ // in steps of 1 degree
// pos1 = 180 - pos; // go from 180 to 1
pos1 = 180 - pos - 1; // go from 179 to 0 - clockwise
myservo.write(pos);
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 1 degrees - clockwise
{
// pos1 = 180 - pos + 1; // go from 1 to 180
pos1 = 180 - pos; // go from 0 to 179 - anticlockwise
myservo.write(pos); // tell servo to go to position in variable 'pos'
myservo1.write(pos1);
delay(15); // waits 15ms for the servo to reach the position
}
}