Tone() how it works?

Hi! everybody, someone knows how the function Tone() makes frequencies?

the digital pins in arduino works with direct current so they have no frequency. -I guess. you can do PWM for simulate an analog output, but you only have 254 values to select.

Now calling the Tone function you can make frequencies from 31 to 65535 values.

i have no idea how this is possible. :o Sorry for my bad english.

Assume you know how to toggle a pin.

If you toggle the pin every 1/2 second you create a 1hertz output frequency. Now if you toggle the pin every 5ms you get 100 hertz. If you toggle a pin every 500us you get 1000hertz.

Ad nauseam.

Yeah, these are square waves, not nice mellow sine waves. That would take a genuine analog output.

Jicamasconchile:
Now calling the Tone function you can make frequencies from 31 to 65535 values.
i have no idea how this is possible. :o

‘tone()’ uses a 16-bit timer, not 8-bit PWM.

Jicamasconchile: i have no idea how this is possible. :o

The tone() function does not create a sine wave of that frequency, it simply creates a square wave of the frequency switching from HIGH to LOW and the other way round.

With PWM, the frequency stays the same, but the % of the pulse that is high changes. 10%, 50%, 90%, etc.

To make different Pitches, you have to change the frequency, not just the mark-space ratio (duty cycle). PWM is not what you are after when you want different frequencies.