Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Tone function with float

  1. #1
    Member dauntless89's Avatar
    Join Date
    Jun 2017
    Location
    Cedar City, UT
    Posts
    55

    Tone function with float

    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.

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,321
    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

  3. #3
    Member dauntless89's Avatar
    Join Date
    Jun 2017
    Location
    Cedar City, UT
    Posts
    55
    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 by dauntless89; 01-30-2020 at 03:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •