All submissions

Solving Approach

How do you plan to solve it?

  1. Connect hardware
    • 4 LEDs → Arduino pins 3, 4, 5, 6 → each with resistor → GND
    • Push button → one leg to pin 2, other leg to GND
  2. Button logic
    • Start with pattern = 0
    • When button is pressed → pattern = (pattern + 1) % 5 (go to next pattern)
  3. LED patterns
    • Pattern 1: all LEDs blink together
    • Pattern 2: blink LED1+3, then LED2+4
    • Pattern 3: blink LED1 → LED2 → LED3 → LED4
    • Pattern 4: blink LED1+2, then LED3+4
    • Pattern 5: blink LED1+4, then LED2+3
  4. Code structure
    • In loop():
      • Read button → update pattern if pressed
      • Use switch(pattern) to decide which LEDs to turn on/off

Code

/*Paste your code here*/

const int buttonPin = 2;
const int led1 = 3;
const int led2 = 4;
const int led3 = 5;
const int led4 = 6;

int pattern = 0;              
int lastButtonState = HIGH;   

void setup() {
  pinMode(buttonPin, INPUT_PULLUP); 
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);

  // detect button press (falling edge)
  if (buttonState == LOW && lastButtonState == HIGH) {
    delay(50);                 
    pattern = (pattern + 1) % 5;  // cycle through 5 patterns (0-4)
  }
  lastButtonState = buttonState;

  // run the active pattern
  switch (pattern) {
    case 0: // Pattern 1: all LEDs blink together
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      digitalWrite(led3, HIGH);
      digitalWrite(led4, HIGH);
      delay(500);
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      delay(500);
      break;

    case 1: // Pattern 2: LED1 & LED3 blink first, then LED2 & LED4
      digitalWrite(led1, HIGH);
      digitalWrite(led3, HIGH);
      delay(500);
      digitalWrite(led1, LOW);
      digitalWrite(led3, LOW);
      delay(500);

      digitalWrite(led2, HIGH);
      digitalWrite(led4, HIGH);
      delay(500);
      digitalWrite(led2, LOW);
      digitalWrite(led4, LOW);
      delay(500);
      break;

    case 2: // Pattern 3: alternate blinking LED1 -> LED2 -> LED3 -> LED4
      digitalWrite(led1, HIGH); delay(300); digitalWrite(led1, LOW);
      digitalWrite(led2, HIGH); delay(300); digitalWrite(led2, LOW);
      digitalWrite(led3, HIGH); delay(300); digitalWrite(led3, LOW);
      digitalWrite(led4, HIGH); delay(300); digitalWrite(led4, LOW);
      break;

    case 3: // Pattern 4: LED1+2 together, then LED3+4 together
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      delay(500);
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      delay(500);

      digitalWrite(led3, HIGH);
      digitalWrite(led4, HIGH);
      delay(500);
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      delay(500);
      break;

    case 4: // Pattern 5: LED1+4 first, then LED2+3
      digitalWrite(led1, HIGH);
      digitalWrite(led4, HIGH);
      delay(500);
      digitalWrite(led1, LOW);
      digitalWrite(led4, LOW);
      delay(500);

      digitalWrite(led2, HIGH);
      digitalWrite(led3, HIGH);
      delay(500);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
      delay(500);
      break;
  }
}

 

 

 

Output

Video

Add a video of the output (know more)

 

 

 

 

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!