#include <ESP32Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define LED_BLUE 32
#define PUSH_BUTTON_1 33
#define PUSH_BUTTON_2 35
#define PUSH_BUTTON_3 34
#define ALARM_PIN 25
#define SDA 13
#define SCL 12
Servo myServo1;
Servo myServo2;
void setup() {
pinMode(LED_BLUE, OUTPUT);
pinMode(PUSH_BUTTON_1, INPUT);
pinMode(PUSH_BUTTON_2, INPUT);
pinMode(PUSH_BUTTON_3, INPUT);
pinMode(ALARM_PIN, OUTPUT);
myServo1.attach(18); // Attach servo to pin 18
myServo2.attach(19);
Serial.begin(115200);
Wire.begin(SDA, SCL); // Conecta o pino I2C.
lcd.init(); // Inicialização do drive do LCD
lcd.backlight();
lcd.setCursor(0,0); // Move o cursor para a linha 0, coluna >
lcd.print("Ligado!");
servo_set_pin(servo_pin);
}
void loop() {
if (digitalRead(PUSH_BUTTON_1) == HIGH) {
// If the button is pressed
digitalWrite(LED_BLUE, HIGH); // Turn on the blue LED
tone(ALARM_PIN, 2000); // Activate the alarm sound
rotateServo(); // Call function to rotate the servo
} if (digitalRead(PUSH_BUTTON_2) == HIGH){
rotateServo();
myServo2.writeMicroseconds(1500);
}
else {
// If the button is not pressed
//digitalWrite(LED_BLUE, LOW); // Turn off the blue LED
noTone(ALARM_PIN); // Turn off the alarm sound
myServo1.writeMicroseconds(1500); // Set servo to the center position (stop rotation)
}
}
void rotateServo() {
// Rotate the servo continuously while the button is pressed
myServo1.writeMicroseconds(2000); // Adjust this value for the desired rotation speed and direction
}