Arduino with blinking lights

Simple blinking light code with Arduino Uno. See code at the end.

Basic idea:

Light on the left side(alphaLed) blink first and after this light next to it starts and will be on until end of the loop. Then alpaLed blinks again and new light starts. This will go over and over until all lights are up. Then all light will be shutdown and loop starts over.

Working code

int alphaLed = 13;
int led1 = 12;
int led2 = 11;
int led3 = 10;
int led4 = 9;
int led5 = 8;

void setup() {
// setup leds
// alphaLed should be the one most left and its the one that blinks in every turn.
// See the video.

pinMode(alphaLed, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}

void loop() {

// Blinking leds. AlphaLed is the first led in line that blinks. AlphaLed blink every time when new led lights up.

digitalWrite(alphaLed, HIGH);
delay(1000);
digitalWrite(alphaLed, LOW);
delay(1000);

// leave led1 on High mode
digitalWrite(led1, HIGH);
delay(1000);

digitalWrite(alphaLed, HIGH);
delay(1000);
digitalWrite(alphaLed, LOW);
delay(1000);

// leave led2 on High mode
digitalWrite(led2, HIGH);
delay(1000);

digitalWrite(alphaLed, HIGH);
delay(1000);
digitalWrite(alphaLed, LOW);
delay(1000);

// leave led3 on High mode
digitalWrite(led3, HIGH);
delay(1000);

digitalWrite(alphaLed, HIGH);
delay(1000);
digitalWrite(alphaLed, LOW);
delay(1000);

// leave led4 on High mode
digitalWrite(led4, HIGH);
delay(1000);

digitalWrite(alphaLed, HIGH);
delay(1000);
digitalWrite(alphaLed, LOW);
delay(1000);

// leave led5 on High mode
digitalWrite(led5, HIGH);
delay(1000);

// Turn off all leds and start all over

digitalWrite(alphaLed, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
delay(2000);

}

What i used:

  • Arduino
  • 6 x Leds
  • Breadboard
  • Jumper Wires

This page is licensed under a GNU General Public License v2

Mainokset

Vastaa

Täytä tietosi alle tai klikkaa kuvaketta kirjautuaksesi sisään:

WordPress.com-logo

Olet kommentoimassa WordPress.com -tilin nimissä. Log Out /  Muuta )

Google photo

Olet kommentoimassa Google -tilin nimissä. Log Out /  Muuta )

Twitter-kuva

Olet kommentoimassa Twitter -tilin nimissä. Log Out /  Muuta )

Facebook-kuva

Olet kommentoimassa Facebook -tilin nimissä. Log Out /  Muuta )

Muodostetaan yhteyttä palveluun %s