#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
int potPin1 = A0; // Potentiometer 1 analog input pin
int potPin2 = A1; // Potentiometer 2 analog input pin
int buttonPin = 2; // Button input pin
int servo3Pin = 11; // Servo 3 control pin
bool buttonState = false;
bool lastButtonState = false;
void setup() {
servo1.attach(9); // Servo 1 control pin
servo2.attach(10); // Servo 2 control pin
servo3.attach(servo3Pin); // Servo 3 control pin
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
int angle1 = map(analogRead(potPin1), 0, 1023, 0, 180); // Read potentiometer 1 angle
int angle2 = map(analogRead(potPin2), 0, 1023, 0, 180); // Read potentiometer 2 angle
servo1.write(angle1); // Set servo 1 angle
servo2.write(angle2); // Set servo 2 angle
buttonState = digitalRead(buttonPin); // Read the state of the button
if (buttonState != lastButtonState) {
if (buttonState == LOW) {
// Button was pressed, move servo3 quickly from angle 0 to 180 and back to 0
for (int angle = 0; angle <= 180; angle++) {
servo3.write(angle);
delay(1);
}
for (int angle = 180; angle >= 0; angle--) {
servo3.write(angle);
delay(5);
}
}
lastButtonState = buttonState;
}
}