/* Creates flame effect by flickering digital ports 2, 3, 4 */ #define NUMLEDS 3 // digital pin numbers of the LEDs const int ledPins[NUMLEDS] = {1,2,3}; // time that the LEDs are on and off const long timeOn[NUMLEDS] = {200, 73, 80}; // milliseconds const long timeOff[NUMLEDS] = {40, 41, 5}; // milliseconds int ledStates[NUMLEDS]; // Generally, you should use "unsigned long" for variables that hold time // The value will quickly become too large for an int to store unsigned long currentMillis = 0; unsigned long previousMillis[NUMLEDS]; // will store last time LED was updated void setup() { // set the digital pins as output: for (int i=0; i= timeOff[ledNum]) { // save the last time you blinked the LED previousMillis[ledNum] = currentMillis; // Turn on ledStates[ledNum] = HIGH; } } else { if (currentMillis - previousMillis[ledNum] >= timeOff[ledNum]) { // save the last time you blinked the LED previousMillis[ledNum] = currentMillis; // Turn on ledStates[ledNum] = LOW; } // set the LED with the ledState of the variable digitalWrite(ledPins[ledNum], ledStates[ledNum]); } }