#include <Servo.h>
Servo myServo;
Servo myServo1;
int const potPin = A0;
int const potPin1 = A1;
int potVal;
int potVal1;
int angle;
int angle1;
int LASTBUTTONSTATE;
int CURRENTBUTTONSTATE;
int LEDSTATE = LOW;
const int BUTTON = 7;
const int LED = 6;
void setup() {
// put your setup code here, to run once:
myServo.attach(9);
myServo1.attach(10);
Serial.begin(9600);
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
CURRENTBUTTONSTATE = digitalRead(BUTTON);
}
void loop() {
// put your main code here, to run repeatedly:
potVal = analogRead(potPin);
potVal1 = analogRead(potPin1);
Serial.print("potVal: ");
Serial.print(potVal1);
angle = map(potVal, 0, 1023, 0, 180);
angle1 = map(potVal1, 0, 1023, 0, 180);
Serial.print(", angle: ");
Serial.println(angle);
myServo.write(angle);
myServo1.write(angle1);
delay(60);
LASTBUTTONSTATE = CURRENTBUTTONSTATE;
CURRENTBUTTONSTATE = digitalRead(BUTTON);
if(LASTBUTTONSTATE == HIGH && CURRENTBUTTONSTATE == LOW){
if(LEDSTATE == LOW)
LEDSTATE = HIGH;
else
LEDSTATE = LOW;
digitalWrite(LED, LEDSTATE);
}
if(LEDSTATE == LOW){
myServo.write(90);
myServo1.write(90);
}
else{
myServo.write(potVal);
myServo1.write(potVal1);
}
}