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?
#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);
}
}
}