#include <ESP32Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define servoP 16
#define botao 14
Servo servoM;
int contagem = 0;
int angulo = 0;
bool botaoatual = 0;
bool botaoanterior = 0;
void setup() {
Serial.begin(115200);
servoM.attach(servoP);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Pressionamentos:");
lcd.setCursor(0, 1);
lcd.print(contagem);
pinMode(botao, INPUT);
}
void loop() {
botaoatual = digitalRead(botao);
if (botaoatual == LOW && botaoanterior == HIGH) {
contagem++;
angulo = (contagem * 10) % 181;
servoM.write(angulo);
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(contagem);
}
botaoanterior = botaoatual;
delay(50);
}