Blue LEDs light up in a Row with a Button

Supplies:

1 – Breadboard 830 Points
1 – Arduino Nano
1 – Push-Button
6 – LEDs
6 – 220 Ohm Resistors

Arduino Code:

int blue1 = 12;
int blue2 = 11;
int blue3 = 10;
int red = 9;
int blue4 = 7;
int blue5 = 6;
int button = 4;

void setup() {

  pinMode(blue1, OUTPUT);
  pinMode(blue2, OUTPUT);
  pinMode(blue3, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(blue4, OUTPUT);
  pinMode(blue5, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  
}

void loop() {

  while (digitalRead(button) == LOW) {

  digitalWrite(blue1, HIGH);
  delay(40);
  digitalWrite(blue1, LOW);
  delay(40);

  digitalWrite(blue2, HIGH);
  delay(40);
  digitalWrite(blue2, LOW);
  delay(40);

  digitalWrite(blue3, HIGH);
  delay(40);
  digitalWrite(blue3, LOW);
  delay(40);

  digitalWrite(red, HIGH);
  delay(40);
  digitalWrite(red, LOW);
  delay(40);

  digitalWrite(blue4, HIGH);
  delay(40);
  digitalWrite(blue4, LOW);
  delay(40);

  digitalWrite(blue5, HIGH);
  delay(40);
  digitalWrite(blue5, LOW);
  delay(40);

  while (digitalRead(button) == HIGH) {
  digitalWrite(blue1, HIGH);
  digitalWrite(blue2, HIGH);
  digitalWrite(blue3, HIGH);
  digitalWrite(red, HIGH);
  digitalWrite(blue4, HIGH);
  digitalWrite(blue5, HIGH);

}
}
}

Leave a Comment

− 4 = 2