Countdown to Christmas Makes Challenge 2017 – Day 5

Project:

Hack-able Christmas Lights

Parts required:

1 x Arduino UNO
1 x Large breadboard
9 x LED’s (3 x Green, 3 x Red, 3 x Yellow)
9 x 220 ohm resistors
19 x Hook-up wires
1 x Power source, either USB or battery

Wiring Diagram:

Code:

// Hack-able Christmas Lights by @KariLawler (Twitter), 05/Dec/17, v1.0

// pin's the leds are attached to
int pinArray[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10 };

// number of pin's used
int pinCount = 9;

// light on/off pattern, 2-dimensional array
// remember, arrays start at 0! i.e. led 1 = 0, led 2 = 1 ... etc
int pattern[3][3] = { { 0, 3, 6 },  { 1, 4, 7 }, { 2, 5, 8 } };

void setup() {
  // initialize each pin as an output
  for (int pin = 0; pin < pinCount; pin++) {
    pinMode(pinArray[pin], OUTPUT);
  }
}

void loop() {
  // loop through each row of pattern
  for(int row = 0; row < 3; row++) {
    // switch on.
    for (int pin = 0; pin < 3; pin++) {
      digitalWrite(pinArray[pattern[row][pin]], HIGH);
    }
    delay(500); // wait 1/2 second
    // switch off
    for (int pin = 0; pin < 3; pin++) {
      digitalWrite(pinArray[pattern[row][pin]], LOW);
    }
  }
}

Leave a Reply