Include pico_tone library#70
Conversation
|
Hi! Just wanted to check in on this PR — it's been open for a while and I wanted to make sure it hasn't been forgotten. Is there anyone actively maintaining this repository? Do you think this change could eventually be merged, or would it be better to close it? No rush at all, just trying to keep things tidy. Thanks! |
| * Adds support for playing tones using PWM. | ||
| * | ||
| * Every sound humans encounter consists of one or more frequencies, and the | ||
| * way the ear interprets those sounds is called pitch. |
There was a problem hiding this comment.
| * way the ear interprets those sounds is called pitch. | |
| * way the ear interprets those sounds is called pitch. |
| } | ||
|
|
||
| void tone(uint gpio, uint freq, uint32_t duration_ms) { | ||
| // Calculate and cofigure new clock divider according to the frequency |
There was a problem hiding this comment.
| // Calculate and cofigure new clock divider according to the frequency | |
| // Calculate and configure new clock divider according to the frequency |
| // This formula is assuming we are running at 125MHz. | ||
| // TODO: Make this work for any frequency |
There was a problem hiding this comment.
Do you want to fix this TODO ? You can use clock_get_hz(clk_sys) to get the actual system clock frequency.
| pwm_set_clkdiv(slice_num, clkdiv); | ||
| // Configure duty to 50% ((2**16)-1)/2) to generate a square wave | ||
| pwm_set_gpio_level(gpio, 32768U); | ||
| sleep_ms(duration_ms); |
There was a problem hiding this comment.
It seems a bit odd for this function to accept a duration_ms parameter, and then sleep for that time, but then leave the tone running afterwards?? Surely it makes more sense to just do
pwm_set_gpio_level(gpio, 32768U);
sleep_ms(duration_ms);
pwm_set_gpio_level(gpio, 0);and then get rid of the separate no_tone function?
It might get merged eventually, but pico-extras and pico-playground are very low on our priority list, and we have more important things to be working on at the moment 😅 |
Fixes #69
This PR was previously made against
pico-sdkbut now requesting to include the library as part ofpico-extrasas per @lurch recommendation.This PR includes tone functions to generate tones using PWM.
The tone function is similar to tone() from Arduino. I have also included a
no_tonefunction to silence buzzer if needed.Inspiration and References: