• It depends a little on your board what's better but basically:

    • setInterval uses the real-time clock (mainly). The CPU can totally go to sleep while it's waiting for the timer, but it's a bit less accurate.
    • digitalPulse uses a dedicated hardware timer. It's more accurate but the CPU's clock has to be on all the time for it to work (even if the CPU itself is sleeping).

    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.

About

Avatar for Gordon @Gordon started