#include <Wire.h> // permite a comunicação do I2C
#include <LiquidCrystal_I2C.h> // biblioteca voltada para o display LCD I2C
#include <ESP32Servo.h> // biblioteca voltada para servo motor
#define pot 34
int switch_b = 13;
LiquidCrystal_I2C LCD (0x27, 16, 2); // identificação do display LCD
const int servoPin = 27; // const é uma variavel constante
Servo servoMotor;
int posGraus = 0;
int lerpot = 0;
bool ler_b = 0;
void setup() {
Serial.begin(115200);
servoMotor.attach(servoPin);
pinMode(switch_b, INPUT);
LCD.init();
LCD.backlight();
LCD.clear();
}
void loop() {
ler_b = digitalRead(switch_b);
lerpot = analogRead(pot);
int lerpot2 = map(lerpot, 0, 4095, 0, 180);
Serial.println(ler_b);
if (digitalRead(switch_b)){
servoMotor.write(lerpot2);
}else {
servoMotor.write(ler_b);
}
LCD.setCursor(0,0);
LCD.print("Servo Motor ON");
LCD.setCursor(0,1);
LCD.print(lerpot2);
delay(20);
//for (posGraus = 0; posGraus <= 180; posGraus ++){
// Serial.println(posGraus);
// servoMotor.write(posGraus);
// delay(20);
//}
//for (posGraus = 180; posGraus >= 0; posGraus --){
// Serial.println(posGraus);
// servoMotor.write(posGraus);
// delay(20);
//}
}