Are tone() and millis() compatible?

Good morning

I would like to know if using tone() may affect the functions using millis() or micros() ?

I read the following in the Tone library documentation:

• Using this library will affect usage of the PWM outputs, so be aware. • Also, although it's the last timer to be allocated, timer 0 (which is used for millis() among other things) will be affected if used.

As tone() seems to have been integrated into Arduino software from this library I am asking the question. I am using a Mega2560 and Arduino022.

Thank you for your answer. Raoul.

The function tone() uses Timer2 on the ATmega328 to generate the tone, so it won’t interfere with millis(), which depends on Timer0. You don’t have to worry.


Thank you Korman. One more question to learn a little bit more, where can I find such information? Raoul.

Raoul, look at the motto below the small picture to the left of this post:

Use the source, Luke.

This is the great thing about an open environment, you have all the source code. If you wonder how something works, what resources something is using, why the stuff doesn’t work you can have a peek at the source and learn interesting stuff. This makes up for incomplete documentation and many other weaknesses. In this case I checked the file hardware/arduino/cores/arduino/Tone.cpp in the Arduino install directory.


Korman Thank you for the tip. Raoul.