Tone function with float

Status
Not open for further replies.

dauntless89

Well-known member
Hello,

I am trying to output a square wave using tone(). The frequency is being returned as a float and I would prefer to output the square wave with the decimals intact, for example 12.34 Hz instead of rounding it off, but it appears the function was written to have an integer passed into it as the scope shows it's outputting a casted frequency.

Is there an easy way to pass floats into tone(), or maybe a different routine that would accomplish the same thing? I need to output two of these signals, and am using a T3.6.

Thanks in advance.
 
tone just uses intervaltimer with microsecond period, and you could make your own variation from Teensy's Tone.cpp, see
hardware/teensy/avr/cores/teensy3/Tone.cpp
 
Looks like it's getting cast to a float anyway. I don't see a reason I can't just alter Tone.cpp to accept a float?
 
Last edited:
Status
Not open for further replies.
Back
Top