#define BUZZER_PIN 22
#define PWM_RESOLUTION 8 // 8-bit resolution (0–255)
void setup() {
// Attach PWM to GPIO 22 with an initial frequency
ledcAttach(BUZZER_PIN, 200, PWM_RESOLUTION);
}
void loop() {
playTone(200, 500); // Low tone
playTone(400, 500); // Medium tone
playTone(600, 500); // High tone
playTone(800, 500); // Higher tone
ledcWrite(BUZZER_PIN, 0); // Stop buzzer
delay(1000);
}
void playTone(int frequency, int duration) {
ledcWriteTone(BUZZER_PIN, frequency); // Generate tone
delay(duration);
}