This sketch works OK apart from the fact that the input on 2 and 3 will work both or either or servo. I would like one button input to control its own servo. Then add more servos with their own buttons. Any help would be very nice thanks.
#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 buttonPin = 2; // The button will be on Pin2
int buttonPin1 =3;
void setup()
{ myservo1. attach(8);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(pos, OUTPUT);
pinMode(pos1,OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buttonPin1,INPUT);
digitalWrite(buttonPin1,LOW);
digitalWrite (buttonPin, LOW);
}
void loop()
{
void();
{
if (digitalRead(buttonPin) == LOW)
for(pos = 0; pos < 30; pos += 30) // goes from 0 degrees to 30 degrees
{ // in steps of degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
}
if (digitalRead(buttonPin) == HIGH)
for(pos = 30; pos>=30; pos-=30) // goes from 30 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay (4000); // waits 4000ms and returns to home position.
}
}
void();
{
if (digitalRead(buttonPin1) == LOW)
for(pos1 = 0; pos1 < 30; pos1 += 30) // goes from 0 degrees to 30 degrees
{ // in steps of degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
}
if (digitalRead(buttonPin1) == HIGH)
for(pos1 = 30; pos1>=30; pos1-=30) // goes from 30 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay (4000); // waits 4000ms and returns to home position.
}
}
}