// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <ESP32Servo.h>
const int servoPin = 13;
const int LED = 4;
const int btn = 2;
bool tam;
static bool previousState = false;
int pos = 0;
Servo servo;
unsigned long debounceDelay = 50;
unsigned long lastDebounceTime = 0;
void setup() {
servo.attach(servoPin, 500, 2400);
pinMode(LED, OUTPUT);
pinMode(btn, INPUT);
servo.write(pos);
}
void loop() {
tam = digitalRead(btn);
if (tam != previousState) {
if ((millis() - lastDebounceTime) >= debounceDelay) {
lastDebounceTime = millis();
if (tam == true) {
digitalWrite(LED, HIGH);
servo.write(90);
}
else {
digitalWrite(LED, LOW);
delay(1000);
servo.write(0);
}
}
}
previousState = tam;
}