Treedix OfficialTreedix OfficialTreedix Official

Snowflake Christmas Xmas Light Source Code

/*
*Project Name:Snowflake
*Features:Allow 36 blue LEDs to flash in multiple modes *
*Version:V1.2
*Description:Add notes
*/
#include <TimerOne.h>

byte m = 0; //mode2 special variable
byte Pvalue = 0; //breathing light brightness variable
boolean BreatheFlag = true; //breathing light brightness direction of change byte ModeNumber = 0; //mode number
boolean AutoModeFlag = false; //automatic change mode identifier
//byte oldModeNumber = 0;
boolean Touchflag = false;
unsigned int Time1 = 0;
unsigned int Time2 = 0;
unsigned int timex = 0;

const byte Ring[5][7]={ {9,10,5}, {8,13,16},

{17,19,12,4,14,7}, {18,2,15}, {11,3,6}
};

void setup() {
Serial.begin(9600);
for(int i=0;i<5;i++){
for(int j=0;Ring[i][j]!='\0';j++){

pinMode(Ring[i][j],OUTPUT); }

}
Timer1.initialize( 100000 ); // initialization, interval use micro sec as a unit Timer1.attachInterrupt( Timer1Interrupt ); // attach the service routine here }

// the setup function runs once when you press reset or power the board void Timer1Interrupt(void){
if((analogRead(A6) > 600) && (Touchflag==false)){

Touchflag = true;
Time1 = millis();
if(!AutoModeFlag){ //increase mode by 1 in non-AUTO mode ModeNumber = ModeNumber + 1;
if(ModeNumber == 2) m = 0;
if(ModeNumber == 13) ModeNumber = 0;
}
//Serial.println(ModeNumber);
}
else if((analogRead(A6) < 600) && (Touchflag==true)){ Touchflag = false;
timex = millis() - Time1;
if(timex > 2000){

ModeNumber = 0; AutoModeFlag = false; }
}

}

// the loop function runs over and over again forever void loop() {
if(AutoModeFlag){

timex = millis() - Time2; if(timex > 5000){ ModeNumber++; Time2 = millis();

}
if(ModeNumber == 12){ AutoModeFlag = false; ModeNumber = 0;
}
}
switch(ModeNumber){

true means brightening

false means fading out

case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10: Mode10(100); break; case 11: Mode6(60); break; case 12: Mode0();

Mode0(); break; Mode1(20); break; Mode7(100); break; Mode2(100); break; Mode8(100); break; Mode11(80); break; Mode4(100); break; Mode3(100); break; Mode5(10); break; Mode9(100); break;

//true means there is a Finger on the TouchPad
//record time1(to press and hold for more than 2s to enter shutdown)
//record time2(to calculate the presentation time of each mode in AUTO mode) //recording time period (shared with Time1 and Time2)

delay(1000); ModeNumber = 1; AutoModeFlag = true; Time2 = millis(); break;

default: break; }

}

/*****************************Light mode 0 function Function name:Mode0
Function feature:Turn off all lights
Input parameter:none

Output parameter:none ******************************************/ void Mode0(void)
{
Ring_Run(0,false);
Ring_Run(1,false);
Ring_Run(2,false);
Ring_Run(3,false);
Ring_Run(4,false);
}

/*****************************Light mode 1 function
Function name:Mode1
Function feature:Outer ring breathing light (internal delay of 10ms) Input parameter:Brightness change interval int Mytime
Output parameter:
******************************************/
void Mode1(int Mytime)
{
analogWrite(Ring[4][1],Pvalue);
analogWrite(Ring[4][2],Pvalue);
if(BreatheFlag==true){

analogWrite(Ring[4][0],255-Pvalue); analogWrite(Ring[0][2],255-Pvalue); Pvalue = Pvalue + 1;
if(Pvalue == 255) BreatheFlag = false; }

if(BreatheFlag==false){ analogWrite(Ring[4][0],255-Pvalue); analogWrite(Ring[0][2],255-Pvalue); Pvalue = Pvalue - 1;

if(Pvalue == 0) BreatheFlag = true; }
delay(10);
}

/*****************************Light mode 2 function
Function name:Mode2
Function feature:From inner ring to outer ring/from outer ring to inner ring Light up and off gradually (the internal will produce a delay of about 5s) Input parameter:
Output parameter:
******************************************/
void Mode2(int Mytime)
{
switch(m){

case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10: delay(4*Mytime); break; case 11: Ring_Run(4,false);break; case 12: delay(Mytime); break; case 13: Ring_Run(3,false);break; case 14: delay(2*Mytime); break; case 15: Ring_Run(2,false);break; case 16: delay(3*Mytime); break; case 17: Ring_Run(1,false);break; case 18: delay(4*Mytime); break; case 19: Ring_Run(0,false);break; case 20: delay(4*Mytime); break; case 21: delay(4*Mytime); break; default: break;

Ring_Run(0,true); break; delay(4*Mytime); break; Ring_Run(1,true); break; delay(3*Mytime); break; Ring_Run(2,true); break; delay(2*Mytime); break; Ring_Run(3,true); break; delay(Mytime); break; Ring_Run(4,true); break; delay(4*Mytime); break;

}
m = m + 1;
if(m == 22) m = 0; }

/*****************************Light mode 3 function
Function name:Mode3
Function feature:Full bright flashing (with a delay of 200ms internally) Input parameter:Flashing half cycle int Mytime
Output parameter:
******************************************/
void Mode3(int Mytime)
{
Ring_Run(0,true);
Ring_Run(1,true);
Ring_Run(2,true);
Ring_Run(3,true);
Ring_Run(4,true);
delay(Mytime);
Ring_Run(0,false);
Ring_Run(1,false);
Ring_Run(2,false);
Ring_Run(3,false);
Ring_Run(4,false);
delay(Mytime);
}

/*****************************Light mode 4 function Function name:Mode4
Function feature:the led at petals light up in rotation Input parameter:Conversion time interval int Mytime Output parameter: ******************************************/

void Mode4(int Mytime)
{ Leaf_Run(2,false);Leaf_Run(0,true);delay(Mytime); Leaf_Run(0,false);Leaf_Run(1,true);delay(Mytime); Leaf_Run(1,false);Leaf_Run(2,true);delay(Mytime); }

/*****************************Light mode 5 function Function name:Mode5
Function feature:Super spin light 1
Input parameter:Conversion time interval int Mytime Output parameter: ******************************************/

void Mode5(int Mytime)
{
digitalWrite(Ring[0][2],LOW);digitalWrite(Ring[0][0],HIGH);delay(Mytime); digitalWrite(Ring[0][0],LOW);digitalWrite(Ring[0][1],HIGH);delay(Mytime); digitalWrite(Ring[0][1],LOW);digitalWrite(Ring[0][2],HIGH);delay(Mytime);
digitalWrite(Ring[0][2],LOW);
digitalWrite(Ring[1][1],LOW);digitalWrite(Ring[1][0],HIGH);delay(Mytime); digitalWrite(Ring[1][0],LOW);digitalWrite(Ring[1][2],HIGH);delay(Mytime); digitalWrite(Ring[1][2],LOW);digitalWrite(Ring[1][1],HIGH);delay(Mytime);
digitalWrite(Ring[1][1],LOW); digitalWrite(Ring[2][4],LOW);digitalWrite(Ring[2][5],LOW);digitalWrite(Ring[2][2],HIGH);digitalWrite(Ring[2][3],HIGH);delay(Mytime); digitalWrite(Ring[2][2],LOW);digitalWrite(Ring[2][3],LOW);digitalWrite(Ring[2][0],HIGH);digitalWrite(Ring[2][1],HIGH);delay(Mytime); digitalWrite(Ring[2][0],LOW);digitalWrite(Ring[2][1],LOW);digitalWrite(Ring[2][4],HIGH);digitalWrite(Ring[2][5],HIGH);delay(Mytime); digitalWrite(Ring[2][4],LOW);digitalWrite(Ring[2][5],LOW);
digitalWrite(Ring[3][2],LOW);digitalWrite(Ring[3][0],HIGH);delay(Mytime); digitalWrite(Ring[3][0],LOW);digitalWrite(Ring[3][1],HIGH);delay(Mytime); digitalWrite(Ring[3][1],LOW);digitalWrite(Ring[3][2],HIGH);delay(Mytime);
digitalWrite(Ring[3][2],LOW);
digitalWrite(Ring[4][2],LOW);digitalWrite(Ring[4][0],HIGH);delay(Mytime); digitalWrite(Ring[4][0],LOW);digitalWrite(Ring[4][1],HIGH);delay(Mytime); digitalWrite(Ring[4][1],LOW);digitalWrite(Ring[4][2],HIGH);delay(Mytime);
digitalWrite(Ring[4][2],LOW);
}

/*****************************Light mode 6 function Function name:Mode6
Function feature:Double neutron star entanglement Input parameter:Conversion time interval int Mytime Output parameter:none ******************************************/

void Mode6(int Mytime)
{
Ring_Run(0,true);
Ring_Run(4,true); digitalWrite(Ring[2][4],LOW);digitalWrite(Ring[2][3],HIGH);delay(Mytime); digitalWrite(Ring[2][3],LOW);digitalWrite(Ring[3][1],HIGH);delay(Mytime); digitalWrite(Ring[3][1],LOW);digitalWrite(Ring[2][2],HIGH);delay(Mytime); digitalWrite(Ring[2][2],LOW);digitalWrite(Ring[2][1],HIGH);delay(Mytime); digitalWrite(Ring[2][1],LOW);digitalWrite(Ring[3][0],HIGH);delay(Mytime); digitalWrite(Ring[3][0],LOW);digitalWrite(Ring[2][0],HIGH);delay(Mytime); digitalWrite(Ring[2][0],LOW);digitalWrite(Ring[2][5],HIGH);delay(Mytime); digitalWrite(Ring[2][5],LOW);digitalWrite(Ring[3][2],HIGH);delay(Mytime); digitalWrite(Ring[3][2],LOW);digitalWrite(Ring[2][4],HIGH);delay(Mytime);

}

/*****************************Light mode 7 function Function name:Mode7
Function feature:Double neutron star entanglement Input parameter:Conversion time interval int Mytime Output parameter:none ******************************************/

void Mode7(int Mytime)
{
Ring_Run(2,false);
Ring_Run(4,true); digitalWrite(Ring[0][2],HIGH);digitalWrite(Ring[1][0],HIGH);delay(Mytime); digitalWrite(Ring[0][2],LOW);digitalWrite(Ring[1][0],LOW);delay(Mytime); digitalWrite(Ring[0][0],HIGH);digitalWrite(Ring[1][1],HIGH);delay(Mytime); digitalWrite(Ring[0][0],LOW);digitalWrite(Ring[1][1],LOW);delay(Mytime); digitalWrite(Ring[0][1],HIGH);digitalWrite(Ring[1][2],HIGH);delay(Mytime); digitalWrite(Ring[0][1],LOW);digitalWrite(Ring[1][2],LOW);delay(Mytime);

}

/*****************************Light mode 8 function Function name:Mode8
Function feature:Double neutron star entanglement Input parameter:Conversion time interval int Mytime Output parameter:none ******************************************/

void Mode8(int Mytime) {
for(int i=0;i<5;i++){

for(int j=0;Ring[i][j]!='\0';j++){ digitalWrite(Ring[i][j],HIGH); delay(Mytime);
}

}
for(int i=0;i<5;i++){
for(int j=0;Ring[i][j]!='\0';j++){

digitalWrite(Ring[i][j],LOW); }

delay(Mytime); }

}

/*****************************Light mode 9 function Function name:Mode9
Function feature:Double neutron star entanglement Input parameter:Conversion time interval int Mytime Output parameter:none ******************************************/

void Mode9(int Mytime) {
for(int i=0;i<5;i++){

for(int j=0;Ring[i][j]!='\0';j++){ digitalWrite(Ring[i][j],HIGH);

}
delay(Mytime);
}
for(int i=0;i<5;i++){
for(int j=0;Ring[i][j]!='\0';j++){ digitalWrite(Ring[i][j],LOW); delay(Mytime);
}
}

}

/*****************************Light mode 10 function Function name:Mode10
Function feature:Double neutron star entanglement Input parameter:Conversion time interval int Mytime Output parameter:none ******************************************/

void Mode10(int Mytime)
{ Ring_Run(0,true);Ring_Run(4,false);delay(Mytime); Ring_Run(1,true);Ring_Run(0,false);delay(Mytime); Ring_Run(2,true);Ring_Run(1,false);delay(Mytime); Ring_Run(3,true);Ring_Run(2,false);delay(Mytime); Ring_Run(4,true);Ring_Run(3,false);delay(Mytime); }

/*****************************Light mode 11 function Function name:Mode11
Function feature:Double neutron star entanglement Input parameter:Conversion time interval int Mytime Output parameter:none ******************************************/

void Mode11(int Mytime) {
for(int i=0;i<3;i++){

digitalWrite(Ring[1][i],HIGH); digitalWrite(Ring[3][i],HIGH); digitalWrite(Ring[4][i],HIGH); delay(Mytime); digitalWrite(Ring[1][i],LOW); digitalWrite(Ring[3][i],LOW); digitalWrite(Ring[4][i],LOW);

// delay(Mytime); }

delay(Mytime); }

/*****************************LED ring operation function Function name:Ring_Run
Function feature:Turn on or off the LED on the designated ring Input parameter:designated ring byte n on/off boolean k Output parameter: ******************************************/

void Ring_Run(byte n,boolean k) {
if(k==true)

switch(n){
case 0:
for(int i = 0;i < 3;i++) digitalWrite(Ring[0][i],HIGH); break; case 1:
for(int i = 0;i < 3;i++) digitalWrite(Ring[1][i],HIGH); break; case 2:
for(int i = 0;i < 6;i++) digitalWrite(Ring[2][i],HIGH); break; case 3:
for(int i = 0;i < 3;i++) digitalWrite(Ring[3][i],HIGH); break; case 4:
for(int i = 0;i < 3;i++) digitalWrite(Ring[4][i],HIGH); break; default : break;
}
else switch(n){
case 0:
for(int i = 0;i < 3;i++) digitalWrite(Ring[0][i],LOW); break; case 1:
for(int i = 0;i < 3;i++) digitalWrite(Ring[1][i],LOW); break; case 2:
for(int i = 0;i < 6;i++) digitalWrite(Ring[2][i],LOW); break; case 3:
for(int i = 0;i < 3;i++) digitalWrite(Ring[3][i],LOW); break; case 4:
for(int i = 0;i < 3;i++) digitalWrite(Ring[4][i],LOW); break; default : break;
}

}

/*****************************LED petal operation function Function name:Leaf_Run
Function feature:Turn on or off the LED on the designated petal Input parameter:Petal number byte n on/off boolean k

Output parameter: ******************************************/ void Leaf_Run(byte n,boolean k)
{
if(k==true)

switch(n){
case 0: digitalWrite(Ring[1][0],HIGH); digitalWrite(Ring[2][0],HIGH); digitalWrite(Ring[2][1],HIGH); digitalWrite(Ring[3][0],HIGH); digitalWrite(Ring[4][0],HIGH); break;
case 1: digitalWrite(Ring[1][2],HIGH); digitalWrite(Ring[2][5],HIGH); digitalWrite(Ring[2][4],HIGH); digitalWrite(Ring[3][2],HIGH); digitalWrite(Ring[4][2],HIGH); break;
case 2: digitalWrite(Ring[1][1],HIGH); digitalWrite(Ring[2][2],HIGH); digitalWrite(Ring[2][3],HIGH); digitalWrite(Ring[3][1],HIGH); digitalWrite(Ring[4][1],HIGH); break;
default: break;
}
else switch(n){
case 0: digitalWrite(Ring[1][0],LOW); digitalWrite(Ring[2][0],LOW); digitalWrite(Ring[2][1],LOW); digitalWrite(Ring[3][0],LOW); digitalWrite(Ring[4][0],LOW); break;
case 1: digitalWrite(Ring[1][2],LOW); digitalWrite(Ring[2][5],LOW); digitalWrite(Ring[2][4],LOW); digitalWrite(Ring[3][2],LOW); digitalWrite(Ring[4][2],LOW); break;
case 2: digitalWrite(Ring[1][1],LOW); digitalWrite(Ring[2][2],LOW); digitalWrite(Ring[2][3],LOW); digitalWrite(Ring[3][1],LOW); digitalWrite(Ring[4][1],LOW); break;
default: break;
}

}

Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
January,February,March,April,May,June,July,August,September,October,November,December
Not enough items available. Only [max] left.
Add to WishlistBrowse WishlistRemove Wishlist
Shopping cart

Your cart is empty.

Return To Shop

Add Order Note Edit Order Note
Estimate Shipping
Add A Coupon

Estimate Shipping

Add A Coupon

Coupon code will work on checkout page