Easy One (not for me)

Hello,

Here's what will probably be an easy one. I have a couple for loops running in the loop that make an LED graph bar go up and down, but I want a couple other LEDs to do some sequential blinking on their own constantly in the background. As it stands I have them blinking once in between each cycle through.

Thank you


int pinsCount=10;                        // declaring the integer variable pinsCount
int pins[] = {1,2,3,4,5,6,7,8,9,10};          // declaring the array pins[]
int ledSide1 = 12;
int ledSide2 = 13;

 
void setup() {                
  for (int i=0; i<pinsCount; i=i+1){    // counting the variable i from 0 to 9
    pinMode(pins[i], OUTPUT);            // initialising the pin at index i of the array of pins as OUTPUT
  }
  pinMode(ledSide1, OUTPUT);
  pinMode(ledSide2, OUTPUT);
}
 
void loop() {

for (int i=0; i<pinsCount; i=i+1){    // chasing right
    digitalWrite(pins[i], HIGH);         // switching the LED at index i on
    delay(50);                          // stopping the program for 100 milliseconds
  //  digitalWrite(pins[i], LOW);          // switching the LED at index i off
  }

   {
  digitalWrite(ledSide1, HIGH);
  delay(100);
  digitalWrite(ledSide1, LOW);
  digitalWrite(ledSide2, HIGH);
  delay(100);
  digitalWrite(ledSide2, LOW);
 }
  
  for (int i=pinsCount-1; i>0; i=i-1){   // chasing left (except the outer leds)
    digitalWrite(pins[i], HIGH);         // switching the LED at index i on
    delay(100);                          // stopping the program for 100 milliseconds
    digitalWrite(pins[i], LOW);          // switching the LED at index i off
  }
  
 {
  digitalWrite(ledSide2, HIGH);
  delay(100);
  digitalWrite(ledSide2, LOW);
  digitalWrite(ledSide1, HIGH);
  delay(100);
  digitalWrite(ledSide1, LOW);
 }
 
}

Look at the Blink Without Delay example in the IDE. If you use that logic, you can run multiple LED sequences.

1 Like

Good Arduino "multitasking" tutorial

1 Like