#define POTENTIOMETER_PIN 35 //ESP32 pin GPIO35 (ADC0) connected to Potentiometer pin
#define LED_PIN 26 //ESP32 pin GPTO26 connected to LED's pin
#define BUZZER_PIN 21
#define ANALOG_THRESHOLD 1000
//the setup routine runs once when you press reset:
void setup() {
//initialize serial communication at 9600 bits per second:
Serial.begin(9600);
//declare LED pin to be an output:
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT); //set ESP32 pin to output mode
}
//the loop routine runs over and over again forever:
void loop() {
//reads the input on analog pin A0 (value between 0 and 4095)
int analogValue = analogRead(POTENTIOMETER_PIN);
//scales it to brightness (value between 0 and 255)
int brightness = map(analogValue, 0, 4095, 0, 255);
//sets the brightness to LED that connects to pin 3
analogWrite(LED_PIN, brightness);
//print out the value
Serial.print("Analog value = ");
Serial.print(analogValue);
Serial.print(" => brightness = ");
Serial.print(brightness);
delay(100);
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
if (analogValue > ANALOG_THRESHOLD)
digitalWrite(BUZZER_PIN, HIGH); //turn on Piezo buzzer
else
digitalWrite(BUZZER_PIN, LOW); //turn off Piezo Buzzer
}