Rogue tone library, mega 2560 r3 and millis() simple problem

I'm finally managing to isolate what has been messing with me with a project and it's been driving me nuts chasing it.

Anyway, using the tone library and enabling any more than two tones (on a Mega 2560 with 6 timers), causes it to not work. I've looked at the cpp, read up on timer pins and conflicts and have tried a load of variations, but it comes down to this:

Put an indicator LED in pin 40 with the - leg tied to ground thru a 1k resistor, and toggle on

Tone tone3;
Tone tone4;

Presto! no longer works.

:frowning:

Anybody have any ideas?

#include <Tone.h>
int blinker = 40;
unsigned long lastTime;
int blinkerState = LOW;
int wait = 200;
Tone tone1;
Tone tone2;
//Tone tone3;
//Tone tone4;
void setup()
{
  pinMode(blinker, OUTPUT);
  tone1.begin(7);
  tone2.begin(6);
//  tone3.begin(5);
//  tone4.begin(4);
}
//__________________________________________________________LOOP  
void loop() 
{
  unsigned long currentMillis=millis();
  if ((currentMillis - lastTime) >=  wait)
  {
    lastTime=currentMillis;
    {
      if (blinkerState == LOW)
      {
        blinkerState = HIGH;
      }
      else
      {
        blinkerState = LOW;

      }
      digitalWrite(blinker, blinkerState);
   }
  }
}

baelthazoar:
Anyway, using the tone library...

Got a link to that "tone library"?

https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

here it is, I think the problem may be in the .cpp, and not identifying the mega 2560,
changing this:

#if defined(AVR_ATmega1280)

to this:

#if defined(AVR_ATmega1280)||(AVR_ATmega2560)

might have fixed it, I'll test it this afternoon.

Thank you for the follow-up.

I believe that did the trick, I'll be able to tell more once I get further along with the envelopes and the hardware.

I also took out all the library inclusions in the .cpp, this seems to work:

#include <arduino.h>
#include "Tone.h"