Blink with millis: processor time shift?

your description above doesn't seem to match what the code does.

consider the following which simplifies the original code, avoiding redundant code.

it sequentially turns each LED on for 200 msec. but i'm not sure it does what you want either

#define MyHW
#ifdef MyHW
const byte Led1 = 10;
const byte Led2 = 11;
const byte Led3 = 12;
const byte Led4 = 13;
const byte Leds [] = { Led1, Led2, Led3, Led4 };

#else
#endif

enum { Off = HIGH, On = LOW };

const long Interval  = 200;

const byte N_LED = sizeof(Leds);
int ledIdx;

unsigned long msecLst;
unsigned long msec;

// -----------------------------------------------------------------------------
void ventilate ()
{
    if ( (msec - msecLst) > Interval)  {
        msecLst = msec;

        digitalWrite (Leds [ledIdx], Off);

        ledIdx++;
        if (N_LED <= ledIdx)
            ledIdx = 0;

        digitalWrite (Leds [ledIdx], On);
    }
}

// -----------------------------------------------------------------------------
void loop ()
{
    msec = millis ();

    ventilate ();
}

// -----------------------------------------------------------------------------
void setup ()
{
    for (unsigned n = 0; n < N_LED; n++)  {
        pinMode      (Leds [n], OUTPUT);
        digitalWrite (Leds [n], Off);
    }
}
1 Like