#include // Pins const int servoPin = 27; // D1 const int buttonPin = 6; // D4 Servo myServo; // Variables int state = 0; int buttonState; int lastButtonState = HIGH; void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); myServo.attach(servoPin, 500, 2400); myServo.write(0); // posición inicial } void loop() { buttonState = digitalRead(buttonPin); // Detectar pulsación (flanco) if (lastButtonState == HIGH && buttonState == LOW) { state++; if (state > 2) state = 0; // Cambiar posición según estado if (state == 0) { myServo.write(0); Serial.println("Position: 0°"); } else if (state == 1) { myServo.write(90); Serial.println("Position: 90°"); } else if (state == 2) { myServo.write(180); Serial.println("Position: 180°"); } delay(200); // debounce } lastButtonState = buttonState; }