Skip to content

Instantly share code, notes, and snippets.

@microtherion
Created July 31, 2014 22:07
Show Gist options
  • Save microtherion/98abd173d14043720c37 to your computer and use it in GitHub Desktop.
Save microtherion/98abd173d14043720c37 to your computer and use it in GitHub Desktop.
//
// Light show "Trittst im Morgenrot daher"
//
enum {
kFlagRed1 = 2,
kFlagRed2,
kFlagRed3,
kFlagWhite,
kMountainBlue,
kSun,
kMountainRed,
};
enum {
kRest = 0,
kNote = (1 << 0),
kProgMask = (7 << 1),
kProgMorgenrot = (0 << 1),
kProgStrahlen = (1 << 1),
kProgAlpenfirn = (2 << 1),
kProgSeeleAhnt = (3 << 1)
};
const uint16_t gSong[] = {
// Trittst im Morgenrot daher
75, kNote|kProgMorgenrot,
25, kNote|kProgMorgenrot,
100, kNote|kProgMorgenrot,
100, kNote|kProgMorgenrot,
75, kNote|kProgMorgenrot,
25, kNote|kProgMorgenrot,
100, kNote|kProgMorgenrot,
100, kRest|kProgMorgenrot,
// Seh ich dich im Strahlenmeer
75, kNote|kProgStrahlen,
25, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
75, kNote|kProgStrahlen,
25, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
100, kRest|kProgStrahlen,
// Dich, Du Hocherhabener, Herrlicher
150, kNote|kProgSeeleAhnt,
50, kNote|kProgSeeleAhnt,
50, kNote|kProgSeeleAhnt,
50, kNote|kProgSeeleAhnt,
150, kNote|kProgSeeleAhnt,
50, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
200, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
200, kNote|kProgSeeleAhnt,
100, kRest|kProgSeeleAhnt,
// Wenn der Alpehfirn sich roetet
75, kNote|kProgAlpenfirn,
25, kNote|kProgAlpenfirn,
100, kNote|kProgAlpenfirn,
100, kNote|kProgAlpenfirn,
150, kNote|kProgAlpenfirn,
50, kNote|kProgAlpenfirn,
50, kNote|kProgAlpenfirn,
50, kNote|kProgAlpenfirn,
300, kNote|kProgAlpenfirn,
200, kNote|kProgAlpenfirn,
100, kRest|kProgAlpenfirn,
// Betet freie Schweizer, betet
75, kNote|kProgAlpenfirn,
25, kNote|kProgAlpenfirn,
100, kNote|kProgAlpenfirn,
100, kNote|kProgAlpenfirn,
150, kNote|kProgAlpenfirn,
50, kNote|kProgAlpenfirn,
100, kNote|kProgAlpenfirn,
200, kNote|kProgAlpenfirn,
100, kNote|kProgAlpenfirn,
200, kNote|kProgAlpenfirn,
100, kRest|kProgAlpenfirn,
// Eure fromme Seele ahnt (2x)
75, kNote|kProgSeeleAhnt,
25, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
75, kNote|kProgSeeleAhnt,
25, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
100, kRest|kProgSeeleAhnt,
75, kNote|kProgSeeleAhnt,
25, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
75, kNote|kProgSeeleAhnt,
25, kNote|kProgSeeleAhnt,
100, kNote|kProgSeeleAhnt,
100, kRest|kProgSeeleAhnt,
// Gott im hehren Vaterland
150, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
200, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
200, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
150, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
300, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
50, kNote|kProgStrahlen,
100, kNote|kProgStrahlen,
200, kNote|kProgSeeleAhnt,
100, kRest|kProgSeeleAhnt,
0, 0
};
int gNote = -1;
long gNext = 0;
long gStart;
long gTempo = 1000; // ms per beat
int gProg;
const long kQuiescent = 0x7FFFFFFF;
void setup() {
Serial.begin(9600);
// The EL channels are on pins 2 through 9
// Initialize the pins as outputs
pinMode(2, OUTPUT); // channel A
pinMode(3, OUTPUT); // channel B
pinMode(4, OUTPUT); // channel C
pinMode(5, OUTPUT); // channel D
pinMode(6, OUTPUT); // channel E
pinMode(7, OUTPUT); // channel F
pinMode(8, OUTPUT); // channel G
pinMode(9, OUTPUT); // channel H
// We also have two status LEDs, pin 10 on the Escudo,
// and pin 13 on the Arduino itself
pinMode(13, OUTPUT);
gStart = millis();
gNext = kQuiescent;
}
void quiescent()
{
const int kFreq = 300;
digitalWrite(kFlagWhite, HIGH);
digitalWrite(kMountainBlue, LOW);
digitalWrite(kMountainRed, LOW);
digitalWrite(kSun, LOW);
switch (((millis()-gStart) % (kFreq *3)) / kFreq) {
case 0:
digitalWrite(kFlagRed1, HIGH);
digitalWrite(kFlagRed2, LOW);
digitalWrite(kFlagRed3, HIGH);
break;
case 1:
digitalWrite(kFlagRed1, HIGH);
digitalWrite(kFlagRed2, HIGH);
digitalWrite(kFlagRed3, LOW);
break;
case 2:
digitalWrite(kFlagRed1, LOW);
digitalWrite(kFlagRed2, HIGH);
digitalWrite(kFlagRed3, HIGH);
break;
}
}
void loop()
{
if (gNext == kQuiescent) {
if (Serial.available() > 0) {
gNext = millis();
gNote = -1;
} else {
quiescent();
}
} else if (Serial.available() > 0)
Serial.read();
if (millis() >= gNext) {
digitalWrite(13, HIGH);
++gNote;
gStart = gNext;
gNext += (gTempo * gSong[gNote*2]) / 100;
if (gNext == gStart) {
gNext = kQuiescent;
return;
}
gProg = gSong[gNote*2+1];
digitalWrite(kFlagRed1, LOW);
digitalWrite(kFlagRed2, LOW);
digitalWrite(kFlagRed3, LOW);
digitalWrite(kFlagWhite, HIGH);
switch (gProg & kProgMask) {
case kProgMorgenrot:
digitalWrite(kMountainBlue, LOW);
digitalWrite(kMountainRed, LOW);
digitalWrite(kSun, LOW);
break;
case kProgStrahlen:
digitalWrite(kMountainBlue, HIGH);
digitalWrite(kMountainRed, LOW);
digitalWrite(kSun, HIGH);
break;
case kProgAlpenfirn:
digitalWrite(kMountainBlue, LOW);
digitalWrite(kMountainRed, HIGH);
digitalWrite(kSun, LOW);
break;
case kProgSeeleAhnt:
digitalWrite(kMountainBlue, HIGH);
digitalWrite(kMountainRed, LOW);
digitalWrite(kSun, LOW);
break;
}
if (gProg & kNote) {
long vibe = gStart+(gTempo * gSong[gNote*2] * 8) / 1000;
int cycle = 0;
Serial.print("Start "); Serial.print(gStart); Serial.print(" Vibe "); Serial.print(vibe); Serial.print(" Next "); Serial.println(gNext);
while (vibe - millis() > 50) {
switch (cycle++ % 3) {
case 0:
digitalWrite(kFlagRed2, HIGH);
digitalWrite(kFlagRed3, LOW);
digitalWrite(kFlagRed1, HIGH);
break;
case 1:
digitalWrite(kFlagRed1, LOW);
digitalWrite(kFlagRed3, HIGH);
digitalWrite(kFlagRed2, HIGH);
break;
case 2:
digitalWrite(kFlagRed1, HIGH);
digitalWrite(kFlagRed2, HIGH);
digitalWrite(kFlagRed3, LOW);
break;
}
delay(50);
}
digitalWrite(kFlagRed1, HIGH);
digitalWrite(kFlagRed2, HIGH);
digitalWrite(kFlagRed3, HIGH);
}
} else {
if (millis() - gStart > 50) {
digitalWrite(13, LOW);
} else {
delay(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment