Running LEDs ; Control multiple LEDs with a for loop

Back to Free Project Ideas

Running LEDs ; Control multiple LEDs with a for loop

This Circuit Blinks 6 LEDS  Attached To the Arduino by Using a

for () loop

  • Arduino Uno
  • Arduino Programming Cable
  • Resistor 220 ohm x 6
  • 5mm LED x 6
  • Breadboard
  • Male to  Male Breadboard Jumper x 7

int timer = 100;           // The higher the number, the slower the timing.

void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}

void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 8; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}

// loop from the highest pin to the lowest:
for (int thisPin = 7; thisPin >= 2; thisPin–) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Free Project Ideas