#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
LiquidCrystal_I2C LCD( 0x27, 16,2);
//servo
const int servoPin = 27;
Servo servoMotor;
int posGraus= 0;
//botão
#define bot 25
void setup() {
Serial.begin(115200);
LCD.init ();
LCD.backlight ();
LCD.setCursor (0,0);
LCD.print("Senai CFP 1.01");
LCD.setCursor (0,1);
LCD.print("TEC.MECATRONICA");
delay(1000);
LCD.clear();
pinMode(bot, INPUT_PULLUP);
servoMotor.attach(servoPin);
servoMotor.write(posGraus);
}
void loop() {
if (digitalRead(bot) == LOW) {
delay(200);
posGraus += 10;
if (posGraus > 180) {
posGraus = 0;
}
servoMotor.write(posGraus);
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("Pos.: ");
LCD.print(posGraus);
LCD.print(" graus");
}
delay(100);
}