Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Code for k4cg arduino LED-project. See https://twitter.com/k4cg/status/380659262600384513
// Startup
void setup() {
// read seed for harder randomization
randomSeed(analogRead(0));
turnoff();
delay(1000);
neon();
delay(3000);
// blink raute once in purple
glow("raute", 175, 94, 112);
delay(1000);
turnoff();
delay(1000);
}
// Runtime
void loop() {
whiteout();
delay(10000);
vollhartausrasten();
delay(10000);
vollausrasten();
delay(2000);
karusell();
delay(10000);
onebyone();
delay(10000);
pulseup();
delay(10000);
hartausrasten();
delay(10000);
}
// Functions
// more usable glow function
void glow(String inst, int r, int g, int b) {
// replaces switch case with if conditions
// because of crappy string comparsion.
if (inst == "raute") {
analogWrite(2, r);
analogWrite(3, g);
analogWrite(4, b);
} else if (inst == "let") {
analogWrite(7, r);
analogWrite(5, g);
analogWrite(6, b);
} else if (inst == "freedom") {
analogWrite(8, r);
analogWrite(9, g);
analogWrite(10, b);
} else if (inst == "ring") {
analogWrite(11, r);
analogWrite(12, g);
analogWrite(13, b);
}
}
// simply turn off all the pins
void turnoff() {
glow("raute", 0, 0, 0);
glow("let", 0, 0, 0);
glow("freedom", 0, 0, 0);
glow("ring", 0, 0, 0);
}
void turnon() {
glow("raute", 255, 255, 255);
glow("let", 255, 255, 255);
glow("freedom", 255, 255, 255);
glow("ring", 255, 255, 255);
}
// do random things
void hartausrasten() {
// random colors 10 times with short delay
// pretty much code duplication in here
for (int i=0; i <= 10; i++) {
int rr = random(0,255);
int gr = random(0,255);
int br = random(0,255);
glow("raute", rr, gr, br);
rr = random(0,255);
gr = random(0,255);
br = random(0,255);
glow("let", rr, gr, br);
rr = random(0,255);
gr = random(0,255);
br = random(0,255);
glow("freedom", rr, gr, br);
rr = random(0,255);
gr = random(0,255);
br = random(0,255);
glow("ring", rr, gr, br);
delay(100);
}
}
// do freedom let glow up in red
void pulseup() {
for (int i=1; i <= 255; i++) {
glow("freedom", i, 0, 0);
delay(30);
}
}
// neon light turn on simulator
void neon() {
int rndwait=0;
for (int i=0; i <= 10; i++) {
turnon();
delay(random(10,100));
turnoff();
delay(random(10,100));
}
turnon();
}
// turn words on one by one
void onebyone() {
turnoff();
for (int pin=0; pin < 4; pin++) {
for (int i=0; i <= 255; i++) {
if(pin == 0)
glow("raute", i, i, i);
else if(pin == 1)
glow("let", i, i, i);
else if(pin == 2)
glow("freedom", i, i, i);
else
glow("ring", i, i, i);
delay(5);
}
}
for (int pin=0; pin < 4; pin++) {
int cr = random(0,255);
int cg = random(0,255);
int cb = random(0,255);
for (int i=0; i <= 255; i++) {
if(pin == 0)
glow("raute", min(cr,i), min(cg,i), min(cb,i));
else if(pin == 1)
glow("let", min(cr,i), min(cg,i), min(cb,i));
else if(pin == 2)
glow("freedom", min(cr,i), min(cg,i), min(cb,i));
else
glow("ring", min(cr,i), min(cg,i), min(cb,i));
delay(5);
}
}
for (int pin=0; pin < 4; pin++) {
for (int i=255; i > 0; i--) {
if(pin == 0)
glow("raute", i, i, i);
else if(pin == 1)
glow("let", i, i, i);
else if(pin == 2)
glow("freedom", i, i, i);
else
glow("ring", i, i, i);
delay(5);
}
}
}
// turns words on and off with random colors
void karusell() {
int interval = 100;
for(int i=0; i<20; i++) {
glow("raute",0,0,0);
delay(interval);
glow("let",0,0,0);
delay(interval);
glow("freedom",0,0,0);
delay(interval);
glow("ring",0,0,0);
delay(interval);
glow("raute",random(0,255),random(0,255),random(0,255));
delay(interval);
glow("let",random(0,255),random(0,255),random(0,255));
delay(interval);
glow("freedom",random(0,255),random(0,255),random(0,255));
delay(interval);
glow("ring",random(0,255),random(0,255),random(0,255));
delay(interval);
}
}
// turns on and off al words in random colors
void vollausrasten() {
for(int i=0; i<100; i++) {
int cr = random(0,255);
int cg = random(0,255);
int cb = random(0,255);
glow("raute",cr,cg,cb);
glow("let",cr,cg,cb);
glow("freedom",cr,cg,cb);
glow("ring",cr,cg,cb);
delay(50);
turnoff();
delay(50);
}
}
// Turns on and off words in random colors
void vollhartausrasten() {
boolean disable = false;
int pin = 0;
for(int i=0; i<3000; i++) {
pin = random(0,4);
if(disable) {
if(pin == 0)
glow("raute", 0, 0, 0);
else if(pin == 1)
glow("let", 0, 0, 0);
else if(pin == 2)
glow("freedom", 0, 0, 0);
else
glow("ring", 0, 0, 0);
disable = false;
} else {
if(pin == 0)
glow("raute",random(0,255),random(0,255),random(0,255));
else if(pin == 1)
glow("let",random(0,255),random(0,255),random(0,255));
else if(pin == 2)
glow("freedom",random(0,255),random(0,255),random(0,255));
else
glow("ring",random(0,255),random(0,255),random(0,255));
disable = true;
}
delay(10);
}
turnoff();
}
// Fades out from white
void whiteout() {
turnon();
for(int i=255; i>0; i--) {
glow("raute",i,i,i);
glow("let",i,i,i);
glow("freedom",i,i,i);
glow("ring",i,i,i);
delay(20);
}
turnoff();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.