const int buttonPin = 14;
const int buzzerPin = 26;
int buttonState = 0;
int volumeValue = 50; // Default volume value
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(buttonPin, INPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
analogWrite(buzzerPin, volumeValue); // Use analogWrite() for volume control
} else {
analogWrite(buzzerPin, 0); // Turn off buzzer if button is not pressed
}
}