Need support? support@freenove.com
ledcWrite(BUZZER_CHN, 512);
ledcWriteTone(BUZZER_CHN, freq);
} else {
ledcWrite(BUZZER_CHN, 0);
ledcWriteTone(BUZZER_CHN, 0);
}
}
The melody playback function. Every time this function is called, a thread will be created to control the buzzer
to play the tune with the specified frequency.
void setMelodyToPlay(int m) {
melody = m;
enableBuzzered = true;
xTaskCreateUniversal(task_Buzzered, "task_Buzzered", 2048, NULL, 1, &taskHandle_Buzzered, 0);
}
Buzzer thread callback function. Each time the thread is executed, the
vTaskDelete(xTaskGetCurrentTaskHandle()) function is automatically called to close its own thread.
void task_Buzzered(void *pvParameters) {
if (enableBuzzered) {
switch (melody) {
……
}
}
vTaskDelete(xTaskGetCurrentTaskHandle());
}