I have a project where I'd like to pulse a buzzer. right now i'm using setInterval as I read that digitalPulse should only be used for short durations (in the microseconds). I also recently realized that pwm can be used for this purpose.
the one thing i dont like about setInterval is that it makes the code harder to read with various nested intervals if I want to have different buzz patterns. why does it say digitalpulse should only be used for short intervals? is there some problem if I want to have it on for a second? or a half second?
which of these will yield best power utilization as well? it's not super-critical but if one is 10x more power than another, i'll do the power efficient one.
It depends a little on your board what's better but basically:
Honestly, digitalPulse will be totally fine to use for what you're doing, since I guess the buzzer won't be on that often.
However nothing would stop you from writing a little utility function that used setTimeout in a more digitalPulse-y style if you really wanted, which could really tidy up your code.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem