Gorbunov Vadim
Created January 7, 2017

LED Christmas Lighting

We are going to make LED Christmas Lighting based on the Arduino MKR1000 board

113
LED Christmas Lighting

Things used in this project

Hardware components

LED (generic)
LED (generic)
×20
Arduino MKR1000
Arduino MKR1000
×1
lan cable
×1
resistor 75 ohm
×6

Story

Read more

Schematics

fd85f8ug1bb3sws_0ScQ8ULmep.png

fqxa0p7g1bbhjre_Oimbvqvgu8.png

Code

Untitled file

Arduino
#define A 8      // PIN defining
#define B 9
#define C 10
#define D 11
#define E 12

#define DELAY 1200

int c[5][4][2] = {
  { {A, B}, {B, A}, {C, A}, {A, C} },      // Pins defining for every LED 1-20
  { {A, D}, {D, A}, {E, A}, {A, E} },
  { {C, B}, {B, C}, {D, B}, {B, D} },  
  { {B, E}, {E, B}, {C, D}, {D, C} },  
  { {C, E}, {E, C}, {D, E}, {E, D} }
};

int frames[][5] = {
  
 {  0b1111,    //0. All LEDS ON
    0b1111,
    0b1111,
    0b1111,
    0b1111
 },
 {  0b0101,    //1. Even LEDs On
    0b0101,
    0b0101,
    0b0101,
    0b0101
 },
 {  0b1010,    //2. Odd LEDS ON
    0b1010,
    0b1010,
    0b1010,
    0b1010
 },
 {  0b1111,    //3. 4 LED train
    0b0000,
    0b0000,
    0b0000,
    0b0000
 },
 {  0b0111,    
    0b1000,
    0b0000,
    0b0000,
    0b0000
 },
 {  0b0001,    
    0b1110,
    0b0000,
    0b0000,
    0b0000
 },
 {  0b0000,    
    0b1111,
    0b0000,
    0b0000,
    0b0000
 },
 {  0b0000,    
    0b0111,
    0b1000,
    0b0000,
    0b0000
 },
 {  0b0000,    
    0b0011,
    0b1100,
    0b0000,
    0b0000
 },
 {  0b0000,    
    0b0001,
    0b1110,
    0b0000,
    0b0000
 },
};

void setup(){
  pinMode( A, INPUT );      // Set all pins as INPUT
  pinMode( B, INPUT );
  pinMode( C, INPUT );
  pinMode( D, INPUT );
  pinMode( E, INPUT );
  Serial.begin(9600);
}

void display( int frame[5], int duration ){
  int times = 0;
  int x = 0;
  int y = 0;

  while( times < duration ){
    for( y = 0; y < 5; y++ ){
      for( x = 0; x < 4; x++ ){
        setup();
        if( frame[y] & (0b1000 >> x) ){
          light( c[y][x] );
          delayMicroseconds(DELAY);
          times++;
        }
      }
    }
  }
}

void light( int pins[2] ){
  pinMode( pins[0], OUTPUT );
  digitalWrite( pins[0], HIGH );

  pinMode( pins[1], OUTPUT );
  digitalWrite( pins[1], LOW );
}


void loop(){
  //test_loop();
  
  int i;
    display( frames[0], 1000 );
    Serial.println("Cycle");
    
    for (int a=0; a <= 10; a++){
      for( i = 1; i < 3; i++ ){
        display( frames[i], 200 );
     }
    }
    for (int a=0; a <= 10; a++){
      for( i = 3; i < 10; i++ ){
        display( frames[i], 200 );
    
    
 }}}

Credits

Gorbunov Vadim

Gorbunov Vadim

1 project • 1 follower

Comments