#include <ESP32Servo.h>
#define SERVO_PIN 21
#define POT_PIN 26
#define LED_PIN 16
#define BUZZ_PIN 13
Servo myservo;
int pos = 0;
void setup() {
Serial.begin(115200);
myservo.attach(SERVO_PIN);
pinMode(POT_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZ_PIN, OUTPUT);
}
void warning(){
for (int i = 0; i < 3; i++){
tone(BUZZ_PIN, 100, 200);
//analogWrite(BUZZ_PIN, LOW);
delay(200);
}
}
void loop() {
// put your main code here, to run repeatedly:
int potValue = analogRead(POT_PIN);
int servoVal = map(potValue, 0, 4095, 0, 180);
Serial.println(potValue);
myservo.write(servoVal);
if (potValue > 3000){
digitalWrite(LED_PIN, HIGH);
warning();
} else {
digitalWrite(LED_PIN, LOW);
}
delay(100);
}