Reputation: 11
I am trying to understand how tone function works. seems like I can use tone function in a non-PWM channel as well. can you please explain how tome() function was written? If a timer was used then how that was implemented?
Upvotes: 0
Views: 1342
Reputation: 28974
The function uses timer interrupts to toggle an output pin.
The timer is set up using the frequency parameter. In the toneBegin function
The pin is toggled for a number of times that is calculated from duration and frequency.
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Tone.cpp
Upvotes: 2