Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Tuesday, 24 December 2013

Christmas lights (led) with Arduino

This is a very quick post just to say Merry Christmas(!) and also to give you a small kick towards LED control using Arduino. I advise you to visit Jeremy Blum's great tutorials then you can quickly put this together.

"ingridients"

  • Arduino panel (can't think of one which you could not use) + USB cable
  • Breadboard
  • Wires
  • 4 LED
  • 4 270 OHM resistor
Let me just share the code here without any schematics of the wiring (straightforward):


const int RED = 13;
const int YELLOW = 12;
const int GREEN = 11;
const int ORANGE = 10;
const int pause = 500;

int programStates[12][4]={
  {HIGH, HIGH, HIGH, HIGH},
  {HIGH, LOW, LOW, LOW},
  {LOW, HIGH, LOW, LOW},
  {LOW, LOW, HIGH, LOW},
  {LOW, LOW, LOW, HIGH},
  {HIGH, LOW, LOW, HIGH},
  {LOW, HIGH, HIGH, LOW},
  {HIGH, LOW, LOW, HIGH},
  {LOW, HIGH, HIGH, LOW},
  {LOW, HIGH, LOW, HIGH},
  {HIGH, LOW, HIGH, LOW},  
  {LOW, LOW, LOW, LOW}
};


void setup() {                

  pinMode(RED, OUTPUT);     
  pinMode(YELLOW, OUTPUT);     
  pinMode(GREEN, OUTPUT);     
  pinMode(ORANGE, OUTPUT);     
  
}

void setLed(int port, int state) {
  
  digitalWrite(port, state);
  
}

void loop() {

  for (int i = 0; i < 12; i++) {
    setLed(RED, programStates[i][0]);
    setLed(YELLOW, programStates[i][1]);
    setLed(GREEN, programStates[i][2]);
    setLed(ORANGE, programStates[i][3]);
    delay(pause);
  }  

}
And let's see it in action:


http://www.youtube.com/watch?v=eaK2H-Soen8
Youtube video