Go Down

Topic: Rogue tone library, mega 2560 r3 and millis() simple problem (Read 2654 times) previous topic - next topic


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.


Anybody have any ideas?

Code: [Select]

#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);
//  tone3.begin(5);
//  tone4.begin(4);
void loop()
  unsigned long currentMillis=millis();
  if ((currentMillis - lastTime) >=  wait)
      if (blinkerState == LOW)
        blinkerState = HIGH;
        blinkerState = LOW;

      digitalWrite(blinker, blinkerState);

Coding Badly



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.

Coding Badly


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"

Go Up