#include <Servo.h>
Servo myservo;
Servo myservo1;
Servo myservo2;
Servo myservo3;
int potpin=A0;
int val;
int potpin2=A1;
int val2;
int angle =90;
int angleStep =5;
#define LEFT 3
#define RIGHT 2
int angle2 =90;
int angleStep2 =5;
#define LEFT2 5
#define RIGHT2 4
void setup() {
myservo1.attach(10);
myservo3.attach(6);
pinMode(LEFT, INPUT_PULLUP);
pinMode(RIGHT, INPUT_PULLUP);
myservo.write(angle);
myservo.attach(11);
pinMode(LEFT2, INPUT_PULLUP);
pinMode(RIGHT2, INPUT_PULLUP);
myservo2.write(angle);
myservo2.attach(9);
}
void loop() {
val=analogRead(potpin);
val=map(val,0,1023,0,180);
myservo1.write(val);
val2=analogRead(potpin2);
val2=map(val2,0,1023,0,180);
myservo3.write(val2);
while(digitalRead(RIGHT2) == LOW){
if (angle2 > 0 && angle2 <= 180) {
angle2 = angle2 - angleStep2;
if(angle2 < 0){
angle2 = 0;
}else{
myservo2.write(angle2); // move the servo to desired angle
}
}
delay(15); // waits for the servo to get there
}
while(digitalRead(LEFT2) == LOW){
// Servo button demo by Robojax.com
if (angle2 >= 0 && angle2 <= 180) {
angle2 = angle2 + angleStep2;
if(angle2 >180){
angle2 =180;
}else{
myservo2.write(angle2); // move the servo to desired angle
}
}
delay(15); // waits for the servo to get there
}
while(digitalRead(RIGHT) == LOW){
if (angle > 0 && angle <= 180) {
angle = angle - angleStep;
if(angle < 0){
angle = 0;
}else{
myservo.write(angle); // move the servo to desired angle
}
}
delay(15); // waits for the servo to get there
}// while
// Servo button demo by Robojax.com
while(digitalRead(LEFT) == LOW){
// Servo button demo by Robojax.com
if (angle >= 0 && angle <= 180) {
angle = angle + angleStep;
if(angle >180){
angle =180;
}else{
myservo.write(angle); // move the servo to desired angle
}
}
delay(15); // waits for the servo to get there
}}