Dual Tone Generation

 

There is a built-in Tone function as part of Arduino-C. It only allows one tone at a time. Like many of Arduino's built-in functions, it loads generic code that can be much larger than a well written stand-alone function.

This function uses a known method of summing a value (the frequency) into a larger variable and looking at some high order bit to change as the result of multiple sums. The advantage of this method is that the total time for the function and the frequency are totally independent. In this case, both frequencies along with the duration can be separately specified.

 

DualTone.ino

(Alt-left-click to download as file)