-1

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?

vahid tajari
  • 1,163
  • 10
  • 20
Rag
  • 1
  • 2

1 Answers1

1

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

Piglet
  • 27,501
  • 3
  • 20
  • 43