Continuous blinking

Hi all...
i need a help

i want to update this code to continuous functioning the Pattern 1 when the other patterns are going as normal.

any suggestions....

thanks :pray: :pray:

// Pin definitions
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4;
const int ledPin4 = 5;
const int ledPin5 = 7;
const int ledPin6 = 8;
const int ledPin7 = 9;
const int ledPin8 = 10;


const int delayTime = 5000;

void setup() {
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
}

void loop() {
 // Pattern 1
  blinkone();
  
  // Pattern 2
  blinkOneByOne();

delay(10);
  
  // Pattern 3
  turnOnOneByOne();
}

void blinkOneByOne() {
  digitalWrite(ledPin1, LOW);
  delay(delayTime);
  digitalWrite(ledPin1, HIGH);
  
  digitalWrite(ledPin2, LOW);
  delay(delayTime);
  digitalWrite(ledPin2, HIGH);
  
  digitalWrite(ledPin3, LOW);
  delay(delayTime);
  digitalWrite(ledPin3, HIGH);
}

void turnOnOneByOne() {
  digitalWrite(ledPin5, LOW);
  delay(500);
  
  digitalWrite(ledPin6, LOW);
  delay(500);
  
  digitalWrite(ledPin7, LOW);
  delay(500);
  
  digitalWrite(ledPin8, LOW);
  delay(10000);
  
  // Turn off all LEDs
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin3, HIGH);
  digitalWrite(ledPin4,HIGH);
  digitalWrite(ledPin5, HIGH);
  digitalWrite(ledPin6, HIGH);
  digitalWrite(ledPin7, HIGH);
  digitalWrite(ledPin8,HIGH);
}

void blinkone(){
  digitalWrite(ledPin4, LOW);
  delay(500);
  
  digitalWrite(ledPin4, HIGH);
  delay(500);
  
}

Please follow the forum guidelines and post your code using code tags. Explain in better detail what you want. You will also have to get rid of the delays as they are blocking and nothing else happens until the delay has timed out.

You won’t like this, but the delay() is killing your chances.

Read up on millis() timing.
Then it’ll get a bit trickier, because you have two or more asynchronous timed events running simultaneously.

In general - Arrays and structs are your friends.
Don't duplicate code in your sketch. Write code once - use it multiple times.

look this over
i only had 4 LEDs to test with
each pattern function uses a timer to do the next thing
the LED pins are defined in an array and an idx used to access the pin

// LED patterns

const byte PinLeds [] = { 10, 11, 12, 13 };
const int Nleds = sizeof (PinLeds);

enum { Off = HIGH, On = LOW };

unsigned long msec;

// -----------------------------------------------------------------------------
// sequentially turn LEDs on, then all off
void
pattern10 (void)
{
    static unsigned long msecLst;
    static int           idx;
    const  int           IdxN = 2;
    const  int           Idx0 = 0;

    if (msec - msecLst >= 500)  {
        msecLst = msec;

        if (IdxN < idx)  {
            idx = Idx0;
            Serial.println ("all off");
            for (int n = Idx0; n <= IdxN; n++)
                digitalWrite (PinLeds [n], Off);  // all off
        }
        else  {
            Serial.println (PinLeds [idx]);
            digitalWrite (PinLeds [idx], On);
            idx++;
        }
    }
}

// -----------------------------------------------------------------------------
// toggle pin
void
pattern13 (void)
{
    static unsigned long msecLst;

    if (msec - msecLst >= 300)  {
        msecLst = msec;
        digitalWrite (PinLeds [3], !  digitalRead (PinLeds [3]));
    }
}

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

    pattern13 ();
    pattern10 ();
}

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

    for (int n = 0; n < Nleds; n++)  {
        pinMode (PinLeds [n], OUTPUT);
        digitalWrite (PinLeds [n], Off);
    }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.