public
Last active

Code for k4cg arduino LED-project. See https://twitter.com/k4cg/status/380659262600384513

  • Download Gist
letfreedomring-k4cg.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
// 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();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.