EasyManua.ls Logo

Freenove ESP32 - Page 100

Default Icon
159 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Need support? support@freenove.com
98
Chapter 8 Buzzer
www.freenove.com
19
20
21
22
23
24
25
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.
40
41
42
43
44
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());
}

Related product manuals