//declared the buzzer pin number
const int BUZZER_PIN = 26;
// setting PWM properties
const int BUZZER_CHANNEL = 1;
const int frequency = 5000;
const int resolution = 8;
void setup_buzzer_channel(){
// configure Buzzer PWM functionalitites
ledcSetup(BUZZER_CHANNEL, frequency, resolution);
// Attach the channel to the Buzzer pin to be controlled
ledcAttachPin(BUZZER_PIN, BUZZER_CHANNEL);
}
void setup() {
// put your setup code here, to run once:
setup_buzzer_channel();
pinMode(BUZZER_PIN,OUTPUT);
Serial.begin(115200);
}
// buzzer tone function
void wizgear_update_buzzer_sound(int freq, double duration){
ledcWriteTone(BUZZER_CHANNEL,freq);
if(duration>0){
delay(duration*1000);
}
}
void loop() {
// put your main code here, to run repeatedly:
wizgear_update_buzzer_sound(8000, 1);
wizgear_update_buzzer_sound(3000, 1);
wizgear_update_buzzer_sound(1000, 1);
delay(1000);
Serial.println("playing music.....");
}