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
Presto! no longer works.
Anybody have any ideas?
int blinker = 40;
unsigned long lastTime;
int blinkerState = LOW;
int wait = 200;
unsigned long currentMillis=millis();
if ((currentMillis - lastTime) >= wait)
if (blinkerState == LOW)
blinkerState = HIGH;
blinkerState = LOW;