#include <Servo.h>
Servo myservoa; // create first servo object to control First servo named myservoa
Servo myservob; // create second servo object to control Second servo named myservob
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int inPin = 7; // choose the input pin(for a pushbutton)
int ledPin = 10; // choose the pin for the LED
int val = 0;
void setup() {
myservoa.attach(9); // attaches the servoA on pin 9 to the servo object
myservob.attach(10); // attaches the servoB on pin 10 to the servo object
pinMode(inPin,OUTPUT); // declare LED as output
pinMode(inPin,INPUT); // declare pushbutton as input
}
void loop() {
val = digitalRead(inPin);
if (val == LOW){
digitalWrite(inPin, LOW); // turn LED OFF
}
else {
digitalWrite(inPin,HIGH); // turn LED ON
if(pos =0; pos<= 180; pos+=10){ // goes from 0 degrees to 180 degrees
// in steps of 5 degrees
myservoa.write(pos); // tell servoA to go to position variable ‘pos’
delay(1500); //waits 1.5 seconds for the for servoA to reach position
myservob.write(pos); // tell servoB to go to position variable ‘pos’
}
digitalWrite(inPin,HIGH); // turn LED ON
if (pos = 180; pos >= 0; pos+=5){ // goes from 180 degrees to 0 degrees
// in steps of 5 degrees
myservob.write(pos); // tell servoB to go to position variable ‘pos’
delay(500); // waits for 1.5 seconds for the servoB to reach position
myservoA.write(pos); // tell servoA to go to position variable ‘pos’
}
explanation:
I want the