Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Little pattern generator for Arduino-controlled Christmas lights
// Christmas light controller
// Drives three TRIAC channels for lights hung on outside of house
// Kenneth Finnegan, 2010
// kennethfinnegan.blogspot.com
#define ROOFL 12
#define ROOFR 11
#define WINDOW 13
void setup() {
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
randomSeed(analogRead(0));
int i;
// Debug pattern to check channel numbers
for (i= 0; i<5; i++) {
digitalWrite(ROOFR, LOW);
digitalWrite(ROOFL, LOW);
digitalWrite(WINDOW, LOW);
delay(500);
digitalWrite(WINDOW, HIGH);
delay(500);
digitalWrite(ROOFL, HIGH);
delay(500);
digitalWrite(ROOFR, HIGH);
delay(500);
}
}
void loop() {
int mode = random(32);
int i, j;
j = random(10) + 5;
//mode = 8;
switch (mode) {
case 1:
case 7:
for (i=0; i<j; i++) {
digitalWrite(WINDOW, HIGH);
delay(700);
digitalWrite(ROOFR, LOW);
delay(300);
digitalWrite(ROOFL, HIGH);
delay(700);
digitalWrite(WINDOW, LOW);
delay(300);
digitalWrite(ROOFR, HIGH);
delay(700);
digitalWrite(ROOFL, LOW);
delay(300);
}
break;
case 2:
for (i=0; i<j; i++) {
digitalWrite(WINDOW, HIGH);
digitalWrite(ROOFR, LOW);
delay(250);
digitalWrite(ROOFL, HIGH);
digitalWrite(WINDOW, LOW);
delay(250);
digitalWrite(ROOFR, HIGH);
digitalWrite(ROOFL, LOW);
delay(250);
}
break;
case 3:
for (i=0; i<4; i++) {
digitalWrite(WINDOW, HIGH);
digitalWrite(ROOFL, HIGH);
digitalWrite(ROOFR, HIGH);
delay(1000);
digitalWrite(WINDOW, LOW);
digitalWrite(ROOFL, LOW);
digitalWrite(ROOFR, LOW);
delay(500);
}
break;
case 4:
digitalWrite(WINDOW, HIGH);
for (i=0; i<j; i++) {
digitalWrite(ROOFR, HIGH);
digitalWrite(ROOFL, LOW);
delay(500);
digitalWrite(ROOFR, LOW);
digitalWrite(ROOFL, HIGH);
delay(500);
}
break;
case 5:
for (i=0; i<j*3; i++) {
digitalWrite(11 + random(3), random(2));
delay(random(1000) + 500);
}
break;
case 6:
for (i= 0; i<5; i++) {
digitalWrite(ROOFR, LOW);
digitalWrite(ROOFL, LOW);
digitalWrite(WINDOW, LOW);
delay(500);
digitalWrite(WINDOW, HIGH);
delay(500);
digitalWrite(ROOFL, HIGH);
delay(500);
digitalWrite(ROOFR, HIGH);
delay(500);
}
break;
case 8:
digitalWrite(WINDOW, HIGH);
for (i=0; i<j/2; i++) {
digitalWrite(ROOFL, HIGH);
delay(100);
digitalWrite(ROOFL, LOW);
delay(800);
digitalWrite(ROOFR, HIGH);
delay(100);
digitalWrite(ROOFR, LOW);
delay(800);
}
break;
case 9:
case 10:
digitalWrite(WINDOW, HIGH);
digitalWrite(ROOFR, HIGH);
digitalWrite(ROOFL, HIGH);
delay(20000);
break;
default:
digitalWrite(ROOFL, HIGH);
digitalWrite(ROOFR, HIGH);
for (i=0; i<10; i++) {
digitalWrite(WINDOW, HIGH);
delay(1000);
digitalWrite(WINDOW, LOW);
delay(1000);
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment