Why another tone library?I'd already written a highly optimized toneAC library because I needed higher volume, volume control, higher frequency, and better quality. However, toneAC uses fixed timer 1 PWM pins so it's not as flexible. Making toneAC work like tone was simple and there would be several advantages over the tone library, so I spent an hour and made NewTone from the toneAC library.

What does it do better/differently?

About 1,200 bytes smaller code size than the Tone library.

Faster execution time.

Exclusive use of port registers for fastest and smallest code.

Higher quality sound output than tone library.

Uses timer 1 which may free up conflicts with the tone library.

How do I use it?It's a plug-in replacement for the standard tone library. Add the include, use NewTone() instead of tone() and noNewTone() instead of noTone() to enjoy the benefits. If you're running out of program space or have a timer conflict with the tone library, this is the library for you. See the sketch below for an example.

Yup, should work with all ATmega microcontrollers. Tested on my Uno and Teensy 2.0, which are totally different. Doesn't hard code port register values so it should work on all platforms. I use the same technique with NewPing and compatibility is universal for any ATmega microcontroller. Will be simple to confirm it works.

Hi have been trying to adapt to use it on Timer "4" on the mega As i can not use it on Timer 1 as it then conflicts width my PWM signals on the MEGA 2560 ;-( I am trying to drive a speedometer as you see i have just tryed to change the 1 to 4 not sure i know what i am doing Any reply greatly appriciatet ;-)

Hi have been trying to adapt to use it on Timer "4" on the mega As i can not use it on Timer 1 as it then conflicts width my PWM signals on the MEGA 2560 ;-( I am trying to drive a speedometer as you see i have just tryed to change the 1 to 4 not sure i know what i am doing Any reply greatly appriciatet ;-)

It doesn't just conflict with the PWM signals, it replaces them. It's by design. Instead, why not just use PWM for timer 4 for whatever else you're doing?

One of the main purposes of NewTone is to use a different timer than the standard tone library.

In any case, I don't really know the ATmega2560 to know off the top of my head if there's any differences between timer 1 and timer 4. Are they identical? For example, if timer 4 doesn't have all the features of timer 1, it won't work. It doesn't appear it's identical as it has 3 pins tied to timer 4 while timer 1 only has 2.

Without diving into the ATmega2560 technical documentation, I'll be hard-pressed to help.

Instead, I would suggest using my ToneAC library (there's an alternate version which uses timer 2). It's superior to NewTone anyway and is already written to use timer 2 and can be assigned to any pins.

I don't find the Due relevant, so I don't consider support for it. Also, as NewTone uses port registers and direct timer calls, it doesn't really work well for the Due which is totally different than the ATmega.

Hi,i've some problems using the cool NewTone Library together with RCSwitch-Library (using interrupt on pin 2)

I can play sound several times correctly (always using the same function), and than it suddenly stopps playing any sound, while everything else is working fine.Shure both libs use timers and this will harm the sound quality, but why isn't it working any more?PLZ gibe advice what i'm doing wrong or if there's an workaround.

i'm still on arduino 1.0.1 and i'm using an arduino nano V3. The code isn't pretty..sorry for that.

// Serial.print("Setting up callbacks for SerialCommands..."); // Setup callbacks for SerialCommand commands //Serial.print("hello [optional arg] (replys welcome string or RE:arg) "); SCmd.addCommand("hello",SayHello); // Echos the string argument back //Serial.print("|P [arg1] [arg2] (processes two arg commands) "); SCmd.addCommand("P",process_command); // Converts two arguments to integers and echos them back //Serial.print("|S [arg] (sends arg) "); SCmd.addCommand("S",process_switch_command); // Converts two arguments to integers and echos them back SCmd.addCommand("BU",BeepUp); // Converts two arguments to integers and echos them back SCmd.addCommand("BD",BeepDown); // Converts two arguments to integers and echos them back SCmd.addCommand("STOP",StopAudio); // Converts two arguments to integers and echos them back SCmd.addCommand("BEEP",Beep); // Converts two arguments to integers and echos them back SCmd.addCommand("ALARM",Alarm); // Converts two arguments to integers and echos them back SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?") //Serial.println("...ok");

I would like to made some music to my robot, but I can't use virtualwire lib with new tone lib because timers is sames for both libraries.I've found another servo lib than original who have same problem. This is fixed.( it is sofware servo: http://playground.arduino.cc/ComponentLib/Servo)

But not with virtual wire.

Virtual wire use timer1 (16 bits resolution). NewTone lib too.

some informations found about timers here: http://letsmakerobots.com/node/28278

Try my toneAC2 library if you want to use timer 2. Also, the standard tone library also uses timer 2. I wrote NewTone and toneAC to use timer 1 if you were having a timer 2 conflict with something else. If timer 1 is your conflict, use the standard tone library or toneAC2.

Hi Tim,Thanks for your work on the various tone libraries. I'm presently building a device that uses one to drive a speaker to play music. I have a question about usage of timers and outputs. I'd like to keep the possibility open to produce two channels of output (concurrently.) In other words I'd like to play the main melody on one digital output and harmony on another digital output. I also prefer to stick with one output/channel. Is there a tone library or combination of libraries that can do this?