luciorocha
Created January 23, 2017 © GPL3+

Santa Claus Leds Tree

LEDs controlled by Arduino to produce sequence blinks.

BeginnerFull instructions provided52
Santa Claus Leds Tree

Things used in this project

Story

Read more

Schematics

Santa Claus Leds Tree

Santa Claus Leds Tree Fritzing Project

Code

SantaClausTreeLeds

Arduino
/* Santa Claus Leds Tree 
   by
   Lucio Agostinho Rocha
   Last update: 21/01/2017
*/

//Com PWM: 3, 5, 6, 9, 10, 11
//Sem PWM: 2, 4, 7, 8, 12 e 13

int numLeds=10;
int led1=13;
int led2=12;
int led3=11;
int led4=10;
int led5=2;
int led6=3;
int led7=4;
int led8=5;
int led9=6;
int led10=7;
int pino[10] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10};

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

void setup() {
  // put your setup code here, to run once:
  for(int i=0; i<numLeds; i++)
     pinMode(pino[i],OUTPUT);
}

void loop() {

int tempo=100;

/*
//1 de cada vez e volta para 1 (fila circular)
for(int i=0;i<3;i++){
  int tempo=100;
  for(int j=0; j<numLeds;j++)
    funcao1(pino[j], tempo);    
}
*/

//1 de cada vez e volta do ltimo
for(int i=0;i<3;i++){  
  for(int j=0; j<numLeds;j++)
    funcao1(pino[j], tempo);    
  for (int j=numLeds-2;j>0;j--)
    funcao1(pino[j], tempo);    
}

  //apenas verdes  
for(int i=0;i<3;i++){
  for(int j=0; j<numLeds;j++){
    j++;
    funcao1(pino[j], tempo);  
   }  
}

//apenas amarelos
for(int i=0;i<3;i++){
  for(int j=0; j<numLeds;j++){
    funcao1(pino[j], tempo);    
    j++;
  }
}

//Vai e volta fileira 1 (horizontal)
for(int i=0;i<3;i++){
  for(int j=0; j<numLeds/2;j++)
    funcao1(pino[j], tempo);    
  for(int j=numLeds/2-2; j>0;j--)
    funcao1(pino[j], tempo);    
}

//Vai e volta fileira 2 (horizontal)
for(int i=0;i<3;i++){
  for(int j=numLeds/2; j<numLeds;j++)
    funcao1(pino[j], tempo);    
  for(int j=numLeds-2; j>numLeds/2;j--)
    funcao1(pino[j], tempo);    
}

//Vai e volta fileira 1 (vertical)
for(int i=0;i<3;i++){
  //Para frente
  for(int j=0; j<numLeds/2;j++){
    funcao1(pino[j], tempo);  
    funcao1(pino[j+(numLeds/2)], tempo);  
  }    
 
  //Para trs
  for(int j=numLeds-1; j>=numLeds/2;j--){
    funcao1(pino[j], tempo);    
    funcao1(pino[j-(numLeds/2)], tempo);  
  }
}

//Pisca apenas nos pinos com PWM 
/* funcao2(pino[2]);
 funcao2(pino[3]);
 funcao2(pino[5]);
 funcao2(pino[7]);
 funcao2(pino[8]);
*/

 //Fade apenas nos pinos com PWM
 /*funcao3(pino[2],50);
 funcao3(pino[3],50); 
 funcao3(pino[5],50);
 funcao3(pino[7],50); 
 funcao3(pino[8],50); 
*/ 

  /*
 vagaLume(pino[2]);
 vagaLume(pino[3]);
 vagaLume(pino[5]);
 vagaLume(pino[7]);
 vagaLume(pino[8]);
 */
  
    
}

void funcao1(int pino, int tempo){
  digitalWrite(pino,HIGH);
  delay(tempo);
  digitalWrite(pino,LOW);
  delay(tempo);
}

//Pisca
void funcao2(int pino){
  
    for(int i=0;i<20;i++){    
      analogWrite(pino, 100);
      delay(50);
      analogWrite(pino, 0);
      delay(50);      
    }
}

void funcao3(int pino, int tempo){

  // set the brightness of pin 9:
  analogWrite(pino, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(tempo);
}

void vagaLume(int pino){

  if (brightness==0){
    analogWrite(pino, brightness);
    delay(3000);
    for(int i=0;i<20;i++){    
      analogWrite(pino, 100);
      delay(50);
      analogWrite(pino, 0);
      delay(50);      
    }//fim for
    delay(3000);
  }
   
  // set the brightness of pin 9:
  analogWrite(pino, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

void funcao0(int pino){
  digitalWrite(pino,LOW);
}

Credits

luciorocha

luciorocha

5 projects • 30 followers
Thanks to Lucio Agostinho.

Comments