// constants won't change
const int buttonPin = 13; // ESP32connected to button's pin
const int LEDPin = 2; // ESP32 pin connected to LED's pin
// variables will change:
// the current state of LED
int lastButtonState; // the previous state of button
int currentButtonState; // the current state of button
int ledState = LOW; //estado atual do led
bool estadocol = false;
void setup() {
Serial.begin(9600); // initialize serial
pinMode(buttonPin, INPUT_PULLUP); // set ESP32 pin to input pull-up mode
pinMode(LEDPin, OUTPUT); // set ESP32 pin to output mode
}
void loop() {
currentButtonState = digitalRead(buttonPin); //faz a primeira leitura
lastButtonState = currentButtonState; // save the last state
currentButtonState = digitalRead(buttonPin); // read new state
if (lastButtonState == HIGH && currentButtonState == LOW) {
delay(50);
digitalWrite(LEDPin, HIGH);
//aqui pra testar se o botão está funcionando
//spoiler -> não está
//aperto ele e nada acontece
}
lastButtonState = currentButtonState; //atualiza o ultimo estado
delay(100);
}