Puzzled on issue with LED

So all work except when s2p = 1

I'm coming out of a pro mini on pins 7 and 8. thru a 330 ohm resister to transistor and to the LED. For s2p i can run it as 2, 3, 4, 5 or 6 and the LED gives me a fast flash as its programed.

The issue is when i run s2p when i run it as s2p = 1 i get a very very dim flicker. but I can change s2p to = 2 and its normal brightness code is below

int st1 = 1;
int st2 = 1;
int s1p = 1;
int s2p = 1;  
  
const int stro1led =  7;         // the pin that the strobe 1 LED is attached to
const int stro2led =  8;   
  
unsigned long s1previousMillis = 0; 
unsigned long s2previousMillis = 0; 

int s1currentState = 0; // Tracks the current step in the sequence
int s2currentState = 0; // Tracks the current step in the sequence

// Strobe 1
// Define the time for each step in milliseconds
const unsigned long s1p1intervals[4] = {15, 100, 15, 1370}; // pattern 1
const unsigned long s1p2intervals[2] = {15, 1485}; // pattern 2
const unsigned long s1p3intervals[2] = {15, 985}; // pattern 3
const unsigned long s1p4intervals[2] = {15, 735}; // pattern 4
const unsigned long s1p5intervals[2] = {15, 585}; // pattern 5


// Strobe 2
// Define the time for each step in milliseconds
const unsigned long s2p1intervals[4] = {15, 100, 15, 1270}; // pattern 1
const unsigned long s2p2intervals[5] = {750, 15, 100,  15,  620}; // pattern 2
const unsigned long s2p3intervals[3] = {750, 15, 735}; // pattern 3
const unsigned long s2p4intervals[3] = {500, 15, 485}; // pattern 4
const unsigned long s2p5intervals[3] = {375, 15, 360}; // pattern 5
const unsigned long s2p6intervals[3] = {300, 15, 285}; // pattern 5


// Define the LED state for each step (LOW = off, HIGH = on)
// Strobe 1
const int s1p1ledStateValues[4] = {HIGH, LOW, HIGH, LOW }; // pattern 1
const int s1p2ledStateValues[2] = {HIGH, LOW}; // pattern 2
const int s1p3ledStateValues[2] = {HIGH, LOW}; // pattern 3
const int s1p4ledStateValues[2] = {HIGH, LOW}; // pattern 4
const int s1p5ledStateValues[2] = {HIGH, LOW}; // pattern 5

// Strobe 2
const int s2p1ledStateValues[4] = {HIGH, LOW, HIGH, LOW}; // pattern 1
const int s2p2ledStateValues[5] = {LOW, HIGH, LOW, HIGH, LOW}; // pattern 2
const int s2p3ledStateValues[3] = {LOW, HIGH, LOW}; // pattern 3
const int s2p4ledStateValues[3] = {LOW, HIGH, LOW}; // pattern 4
const int s2p5ledStateValues[3] = {LOW, HIGH, LOW}; // pattern 5
const int s2p6ledStateValues[3] = {LOW, HIGH, LOW}; // pattern 6

void setup() {
//  pinMode(stro1led, OUTPUT);
//  digitalWrite(stro1led, LOW); // Start with the LED off
//  pinMode(stro2led, OUTPUT);
//  digitalWrite(stro2led, LOW); // Start with the LED off
}

void loop() {
// Strobe
  unsigned long s1currentMillis = millis();
  unsigned long s2currentMillis = millis();
// Strobe 1
  //pattern 1
  // Check if it is time to switch to the next step
  if (st1 == 1 && s1p == 1 ){ 
  if (s1currentMillis - s1previousMillis >= s1p1intervals[s1currentState]) {
    s1previousMillis = s1currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 3)
    s1currentState = (s1currentState + 1) % 4; 

    // Apply the new LED state
    digitalWrite(stro1led, s1p1ledStateValues[s1currentState]);
  }
}
  //pattern 2
  // Check if it is time to switch to the next step
  else if (st1 == 1 && s1p == 2 ){ 
  if (s1currentMillis - s1previousMillis >= s1p2intervals[s1currentState]) {
    s1previousMillis = s1currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 1)
    s1currentState = (s1currentState + 1) % 2; 

    // Apply the new LED state
    digitalWrite(stro1led, s1p2ledStateValues[s1currentState]);
  }
}
  //pattern 3
  // Check if it is time to switch to the next step
  else if (st1 == 1 && s1p == 3 ){ 
  if (s1currentMillis - s1previousMillis >= s1p3intervals[s1currentState]) {
    s1previousMillis = s1currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 1)
    s1currentState = (s1currentState + 1) % 2; 

    // Apply the new LED state
    digitalWrite(stro1led, s1p3ledStateValues[s1currentState]);
  }
}
  //pattern 4
  // Check if it is time to switch to the next step
  else if (st1 == 1 && s1p == 4 ){ 
  if (s1currentMillis - s1previousMillis >= s1p4intervals[s1currentState]) {
    s1previousMillis = s1currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 1)
    s1currentState = (s1currentState + 1) % 2; 

    // Apply the new LED state
    digitalWrite(stro1led, s1p4ledStateValues[s1currentState]);
  }
}
  //pattern 5
  // Check if it is time to switch to the next step
  else if (st1 == 1 && s1p == 5 ){ 
  if (s1currentMillis - s1previousMillis >= s1p5intervals[s1currentState]) {
    s1previousMillis = s1currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 1)
    s1currentState = (s1currentState + 1) % 2; 

    // Apply the new LED state
    digitalWrite(stro1led, s1p5ledStateValues[s1currentState]);
  }
}
else {
    digitalWrite(stro1led, LOW);
  }   //  led off
  
// Strobe 2
 //pattern 1
  // Check if it is time to switch to the next step
  if (st2 == 1 && s2p == 1 ){ 
  if (s2currentMillis - s2previousMillis >= s2p1intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 3)
    s2currentState = (s2currentState + 1) % 4; .
    // Apply the new LED state
    digitalWrite(stro2led, s2p1ledStateValues[s2currentState]);
  }
}
  //pattern 2
  // Check if it is time to switch to the next step
  if (st2 == 1 && s2p == 2 ){ 
  if (s2currentMillis - s2previousMillis >= s2p2intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 4)
    s2currentState = (s2currentState + 1) % 5; 

    // Apply the new LED state
    digitalWrite(stro2led, s2p2ledStateValues[s2currentState]);
  }
}
  //pattern 3
  // Check if it is time to switch to the next step
  else if (st2 == 1 && s2p == 3 ){ 
  if (s2currentMillis - s2previousMillis >= s2p3intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 2)
    s2currentState = (s2currentState + 1) % 3; 

    // Apply the new LED state
    digitalWrite(stro2led, s2p3ledStateValues[s2currentState]);
  }
}
  //pattern 4
  // Check if it is time to switch to the next step
  else if (st2 == 1 && s2p == 4 ){ 
  if (s2currentMillis - s2previousMillis >= s2p4intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 2)
    s2currentState = (s2currentState + 1) % 3; 

    // Apply the new LED state
    digitalWrite(stro2led, s2p4ledStateValues[s2currentState]);
  }
}
  //pattern 5
  // Check if it is time to switch to the next step
  else if (st2 == 1 && s2p == 5 ){ 
  if (s2currentMillis - s2previousMillis >= s2p5intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 2)
    s2currentState = (s2currentState + 1) % 3; 

    // Apply the new LED state
    digitalWrite(stro2led, s2p5ledStateValues[s2currentState]);
  }
}
  //pattern 6
  // Check if it is time to switch to the next step
  else if (st2 == 1 && s2p == 6 ){ 
  if (s2currentMillis - s2previousMillis >= s2p6intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 2)
    s2currentState = (s2currentState + 1) % 3; 

    // Apply the new LED state
    digitalWrite(stro2led, s2p6ledStateValues[s2currentState]);
  }
}
else {
    digitalWrite(stro2led, LOW);
  }   //  led off


}

With these lines commented out your LED pins are inputs, not outputs. All a digitalWrite(pin, HIGH) does in that instance is to enable the 20-50K pullup resistor on the pin. Which may or may not be enough to turn on your unnamed transistor and unshown circuit.

And your coding/commenting style obscured a missing else in a very effective manner.

// Strobe 2
 //pattern 1
  // Check if it is time to switch to the next step
  if (st2 == 1 && s2p == 1 ){ 
  if (s2currentMillis - s2previousMillis >= s2p1intervals[s2currentState]) {
    s2previousMillis = s2currentMillis; // Save the time of the change

    // Move to the next state (loops back to 0 after 3)
    s2currentState = (s2currentState + 1) % 4; .
    // Apply the new LED state
    digitalWrite(stro2led, s2p1ledStateValues[s2currentState]);
  }
}
  //pattern 2
  // Check if it is time to switch to the next step
  if (st2 == 1 && s2p == 2 ){  // <--- MISSING ELSE BEFORE THE IF!!!!!!!!!

It caused this clause to be executed every time through the loop when st1 was 1 and s2p was 1.

else {
    digitalWrite(stro2led, LOW);
  }   *//  led off*

Thank you. That was a copy and past blunder

That's an inevitable problem with poorly formatted copied and pasted code. You could get rid of a whole lot of it. Here's 5 minutes thought on it. I don't claim it's great code, but it is shorter and doesn't have multiple almost alike blocks of code. Still too many magic numbers for my liking. A couple of class instances would probably be even better.

int s1p = 1;
int s2p = 1;

const int stro1led = 7;  // the pin that the strobe 1 LED is attached to
const int stro2led = 8;

unsigned long s1previousMillis = 0;
unsigned long s2previousMillis = 0;

int s1currentState = 0;  // Tracks the current step in the sequence
int s2currentState = 0;  // Tracks the current step in the sequence

typedef struct {
   unsigned long interval;
   int value;
} Step;

typedef struct {
   int numSteps;
   Step step[5];
} Steps;

Steps stro1[5] = {
   { 4, { { 15, HIGH }, { 100, LOW }, { 15, HIGH }, { 370, LOW } } },
   { 2, { { 15, HIGH }, { 1485, LOW } } },
   { 2, { { 15, HIGH }, { 985, LOW } } },
   { 2, { { 15, HIGH }, { 735, LOW } } },
   { 2, { { 15, HIGH }, { 585, LOW } } }
};
Steps stro2[6] = {
   { 4, { { 15, HIGH }, { 100, LOW }, { 15, HIGH }, { 1270, LOW } } },
   { 5, { { 750, LOW }, { 15, HIGH }, { 100, LOW }, { 15, HIGH }, { 620, LOW } } },
   { 3, { { 750, LOW }, { 15, HIGH }, { 735, LOW } } },
   { 3, { { 500, LOW }, { 15, HIGH }, { 485, LOW } } },
   { 3, { { 375, LOW }, { 15, HIGH }, { 360, LOW } } },
   { 3, { { 300, LOW }, { 15, HIGH }, { 285, LOW } } }
};

void setup() {
   pinMode(stro1led, OUTPUT);
   digitalWrite(stro1led, LOW);  // Start with the LED off
   pinMode(stro2led, OUTPUT);
   digitalWrite(stro2led, LOW);  // Start with the LED off
}

void loop() {
   // Strobe
   unsigned long now = millis();

   switch( s1p ) {
      case 1 ... 5:
         if( now - s1previousMillis >= stro1[s1p - 1].step[s1currentState].interval ) {
            s1previousMillis = now;  // Save the time of the change
            s1currentState = (s1currentState + 1) % stro1[s1p - 1].numSteps;
            digitalWrite(stro1led, stro1[s1p - 1].step[s1currentState].value);
         }
         break;
      default:
         digitalWrite(stro1led, LOW);
         break;
   }

   switch( s2p ) {
      case 1 ... 6:
         if( now - s2previousMillis >= stro2[s2p - 1].step[s2currentState].interval ) {
            s2previousMillis = now;  // Save the time of the change
            s2currentState = (s2currentState + 1) % stro2[s2p - 1].numSteps;
            digitalWrite(stro2led, stro2[s2p - 1].step[s2currentState].value);
         }
         break;
      default:
         digitalWrite(stro2led, LOW);
         break;
   }
}

look the code below over

  • it uses a function as well makes other changes to avoid a lot of redundant code that makes reading the code difficult.
  • tgl() also simply toggles the LED rather than using your LedValue arrays (i should have deleted all the LedValue arrays)
  • i also shortened a lot of variable names to reduce the length of lines also making it easier to read the code
  • also added some debugging prints
  • as well as code to change the sp1 and sp2 values from the monitor which is likely a next step

there are additional changes that could further simplify and enhance the code such as specifying the time intervals thru a serial monitor cmd

int st1 = 1;
int st2 = 1;
int s1p = 1;
int s2p = 1;

const int PinLed1 =  7;
const int PinLed2 =  8;

enum { Off = HIGH, On = LOW };

unsigned long msec;
unsigned long msec1lst = 0;
unsigned long msec2lst = 0;

int s1Idx = 0; // index of s1p1intervals []
int s2Idx = 0;

// Strobe 1
// Define the time for each step in milliseconds
const unsigned long s1p1intervals [4] = {900, 100, 1500, 100}; // pattern 1
// const unsigned long s1p1intervals [4] = {15, 100, 15, 1370}; // pattern 1
const unsigned long s1p2intervals [2] = {15, 1485}; // pattern 2
const unsigned long s1p3intervals [2] = {15, 985}; // pattern 3
const unsigned long s1p4intervals [2] = {15, 735}; // pattern 4
const unsigned long s1p5intervals [2] = {15, 585}; // pattern 5

// Strobe 2
// Define the time for each step in milliseconds
// const unsigned long s2p1intervals [4] = {15, 100, 15, 1270}; // pattern 1
const unsigned long s2p1intervals [4] = {900, 900, 1500, 1500}; // pattern 1
const unsigned long s2p2intervals [5] = {750, 15, 100,  15,  620}; // pattern 2
const unsigned long s2p3intervals [3] = {750, 15, 735}; // pattern 3
const unsigned long s2p4intervals [3] = {500, 15, 485}; // pattern 4
const unsigned long s2p5intervals [3] = {375, 15, 360}; // pattern 5
const unsigned long s2p6intervals [3] = {300, 15, 285}; // pattern 5

// Define the LED state for each step (LOW = off, HIGH = on)
// Strobe 1
const int s1p1ledVal [4] = {HIGH, LOW, HIGH, LOW }; // pattern 1
const int s1p2ledVal [2] = {HIGH, LOW}; // pattern 2
const int s1p3ledVal [2] = {HIGH, LOW}; // pattern 3
const int s1p4ledVal [2] = {HIGH, LOW}; // pattern 4
const int s1p5ledVal [2] = {HIGH, LOW}; // pattern 5

// Strobe 2
const int s2p1ledVal [4] = {HIGH, LOW, HIGH, LOW}; // pattern 1
const int s2p2ledVal [5] = {LOW, HIGH, LOW, HIGH, LOW}; // pattern 2
const int s2p3ledVal [3] = {LOW, HIGH, LOW}; // pattern 3
const int s2p4ledVal [3] = {LOW, HIGH, LOW}; // pattern 4
const int s2p5ledVal [3] = {LOW, HIGH, LOW}; // pattern 5
const int s2p6ledVal [3] = {LOW, HIGH, LOW}; // pattern 6

char s [90];


// -----------------------------------------------------------------------------
bool                // return true if timer expired
tgl (
    const int            Pin,
    unsigned long       &msecLst,
    const unsigned long *Interval,
    int                 &idx,
    int                  Nidx )

{
    if (msec - msecLst >= Interval [idx]) {
        msecLst  = msec;                    // update timestamp when expire
        idx      = (idx +1) % Nidx;         // advance index
        digitalWrite (Pin, !  digitalRead (Pin));

        sprintf (s, "tgl: pin %d, %6lu %6lu ms, %d idx",
                    Pin, msecLst, Interval [idx], idx);
        Serial.println (s);

        return true;
    }
    return false;
}

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


    if (st1 == 1)  {
        if (s1p == 1)  {
            int Ninterval = sizeof(s1p1intervals) /sizeof(long);
            tgl (PinLed1, msec1lst, s1p1intervals, s1Idx, Ninterval);
        }

        else if (s1p == 2)  {
            int Ninterval = sizeof(s1p2intervals) /sizeof(long);
            if (tgl (PinLed1, msec1lst, s1p2intervals, s1Idx, Ninterval))
                Serial.println (" st1 2");
        }

        else if (s1p == 3)  {
            int Ninterval = sizeof(s1p3intervals) /sizeof(long);
            if (tgl (PinLed1, msec1lst, s1p3intervals, s1Idx, Ninterval))
                Serial.println (" st1 3");
        }

        else if (s1p == 4)  {
            int Ninterval = sizeof(s1p4intervals) /sizeof(long);
            if (tgl (PinLed1, msec1lst, s1p4intervals, s1Idx, Ninterval))
                Serial.println (" st1 4");
        }

        else if (s1p == 5)  {
            int Ninterval = sizeof(s1p5intervals) /sizeof(long);
            if (tgl (PinLed1, msec1lst, s1p5intervals, s1Idx, Ninterval))
                Serial.println (" st1 5");
        }
        else
            digitalWrite (PinLed1, Off);
    }


    // ---------------------------------------------------------
    if (st2 == 1)  {
        if (s2p == 1) {
            int Ninterval = sizeof(s2p1intervals) /sizeof(long);
            tgl (PinLed2, msec2lst, s2p1intervals, s2Idx, Ninterval);
        }

        if (s2p == 2) {
            int Ninterval = sizeof(s2p2intervals) /sizeof(long);
            tgl (PinLed2, msec2lst, s2p2intervals, s2Idx, Ninterval);
        }

        if (s2p == 3) {
            int Ninterval = sizeof(s2p3intervals) /sizeof(long);
            tgl (PinLed2, msec2lst, s2p3intervals, s2Idx, Ninterval);
        }

        if (s2p == 4) {
            int Ninterval = sizeof(s2p4intervals) /sizeof(long);
            tgl (PinLed2, msec2lst, s2p4intervals, s2Idx, Ninterval);
        }

        if (s2p == 5) {
            int Ninterval = sizeof(s2p5intervals) /sizeof(long);
            tgl (PinLed2, msec2lst, s2p5intervals, s2Idx, Ninterval);
        }

        if (s2p == 6) {
            int Ninterval = sizeof(s2p6intervals) /sizeof(long);
            tgl (PinLed2, msec2lst, s2p6intervals, s2Idx, Ninterval);
        }

        else
            digitalWrite (PinLed2, LOW);
    }

    // ---------------------------------------------------------
    if (Serial.available ())  {
        char buf [90];
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';             // terminate string with nul

        int m, p;
        sscanf (buf, "%d %d", &m, &p);      // extract 2 values

        if (1 == m)
            s1p = p;
        else if (2 == m)
            s2p = p;
        
        sprintf (s, "   s1p %d, s2p %d", s1p, s2p);
        Serial.println (s);
    }
}


// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin (9600);

    pinMode      (PinLed1, OUTPUT);
    digitalWrite (PinLed1, Off);
    pinMode      (PinLed2, OUTPUT);
    digitalWrite (PinLed2, Off);
}

Thanks for the info. this is a small section of the over all code. I love to build sections at a time and then pile them all into one when done. Yes I agree I could shorten some of the variables, But I'm new to this and for me it helps to clearly say what I'm doing. For sp1 and sp2 that will be pulled from eeprom. I tried your code and it did not work for what I'm looking for

did the LEDs not toggle? did you adjust the timing?

when i load only your script I get led1 a very dim flicker. for led 2 it stays lit bright and then flickers off and back on

Did the code as posted by @gcjr in post #6 compile for you with no modification ?

for pin 1 is ok, pin two its flashing faster then it should

i changed the timing for LED1 to better see if it was doing what was expected. delete the line i added and uncomment the original line

i had also added a print to tgl(). does the timing of the print match the timing specified?

no doubt your confused by much of this. You wrote a lot of code and got snagged by a simple typo. All that code suggests you're interested in driving multiple LED with different patterns. the drawback of your approach is needing to recompile to change the pattern

the following may or may not interest you, but seems like where you're headed and demonstrates various coding techniques that may accelerate your progress.

the code allows you to specifify a pattern of 8 values for up 5 different LEDs thru the Serial monitor using a command such as

pat 10 500 500 100 900

to specify led pin 10 turn on/off for 500/500, then 100/900

the following cmd, without any timing disables that pattern for the specified led pin

pat 10

the code captures the 5 LED patterns in an array of structures, a but simpler that your multiple arrays

struct Pat {
    byte          pinLed;
    unsigned long msec [8];
    unsigned long msec0;
    int           N;
    int           idx;
} pats [Npats];

the code has the following functions

  • void patDisp () - display the current structure values
  • patFind () - searches the structs for a matching led pin
  • void patSet () - sets the pattern parameters
  • void patterns () - invoked repeatedly to update the LED states
  • void procCmd () - processes serial monitor input
  • void loop ()
  • void setup ()
// interactively specify LED pattern thru serial monitor

const char * Version = "LED patters 260825a";

enum { LedOff = HIGH, LedOn = LOW };

unsigned long msec;

char s [90];

// -----------------------------------------------------------------------------
const int Npats = 5;

struct Pat {
    byte          pinLed;
    unsigned long msec [8];
    unsigned long msec0;
    int           N;
    int           idx;
} pats [Npats];
//
// -------------------------------------
void patDisp ()
{
    Serial.println ("  patDsp:");

    for (int p = 0; p < Npats; p++)  {
        sprintf (s, "    pin %2d, N %d", pats [p].pinLed, pats [p].N);
        Serial.print (s);

        for (int n = 0; n < pats [p].N; n++)  {
            sprintf (s, " %5lu", pats [p]. msec[n]);
            Serial.print (s);
        }
        Serial.println (" msec");
    }
    Serial.println ();
}

// -------------------------------------
const int NoPat = -1;

int
patFind (
    int pin )
{
    // find existing pattern
    for (int n = 0; n < Npats; n++)  {
        if (pats [n].pinLed == pin)
            return n;
    }

    // find unused pattern
    for (int n = 0; n < Npats; n++)  {
        if (pats [n].N == 0)
            return n;
    }

    return NoPat;
}

// -------------------------------------
// sets the parameters for specified pattern index
void patSet (
    int   patIdx,
    int  *val,
    int   N )
{
    pats [patIdx].pinLed = val [0];

    for (int n = 1; n < N; n += 2)  {
        pats [patIdx].msec [n-1] = val [n];
        pats [patIdx].msec [n]   = val [n+1];
    }
    pats [patIdx].N = N-1;

    pinMode (pats [patIdx].pinLed, OUTPUT);
}

// -------------------------------------
// update the LED state depending on patterns
void patterns ()
{
    for (int n = 0; n < Npats; n++)  {
        if (! pats [n].N)
            continue;

        if (msec - pats [n].msec0 >= pats [n].msec [pats [n].idx])  {
            pats [n].msec0 += pats [n].msec [pats [n].idx];
        
            // toggle led pin
            digitalWrite (pats [n].pinLed, ! digitalRead (pats [n].pinLed));

            if (++pats [n].idx >= pats [n].N)       // advance idx
                pats [n].idx = 0;
        }
    }
}

// -----------------------------------------------------------------------------
void procCmd (
    char *cmd,
    int  *val,
    int   N )
{
    // -------------------------------------
    // debug
    sprintf (s, "    procCmd: %s", cmd);
    Serial.print (s);

    for (int n = 0; n < N; n++)  {
        sprintf (s, " %d", val [n]);
        Serial.print (s);
    }
    Serial.println ();

    // -------------------------------------
    if (! strcmp (cmd, "disp"))
        patDisp ();

    else if (! strcmp (cmd, "pat"))  {
        if (1 > N)  {
            Serial.print ("  procCmd: pat insufficient # of arguments");
            Serial.print ("    procCmd: pat pin# tOn tOff <tOn tOff>");

            return;
        }

        int idx = patFind (val [0]);
        if (NoPat == idx)  {
            Serial.print ("  procCmd: unknown pattern");
            return;
        }

        if (3 > N)  {
            digitalWrite (pats [idx].pinLed, LedOff);
            pats [idx].N = 0;           // clear
        }
        else
            patSet (idx, val, N);
    }
}

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

    // update LEDs
    patterns ();

    // check for serial monitor command
    if (Serial.available ())  {
        char buf [90];
        int  n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';     // terminate string with nul

        char       cmd [9];
        const int  V = 9;
        int        v [V];
        int        N = sscanf (buf, "%s %d %d %d %d %d %d %d %d %d", cmd,
             &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8] );
        procCmd (cmd, v, N-1);      // don't count cmd
    }
}

// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin   (9600);
    Serial.println (Version);
}