box-o-sand/oldstuff/arduino/misc/ConnecticutHalftime/ConnecticutHalftime.ino
2015-06-22 13:15:42 -05:00

64 lines
1.6 KiB
C++

const unsigned int LED_PIN = 13;
const unsigned int NOTE_MULTIPLIER = 100;
const unsigned int QUARTER_NOTE = 8;
const unsigned int EIGHTH_NOTE = 4;
const unsigned int SIXTEENTH_NOTE = 2;
const unsigned int THIRTYSECOND_NOTE = 1;
int measure0[] = {-8, -8, -8, 2, 2, 2, 2, 0};
int measure1[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
int measure2[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
int measure3[] = {4, 4, 4, 4, 4, 4, 4, 4, 0};
int measure4[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
int measure5[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
int measure6[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
int measure7[] = {4, 4, 4, 4, 4, 4, 4, 4, 0};
int measure8[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
int measurePop[] = {4, -4, -8, -8, -8, 0};
void playNote(int note) {
if (note > 0) {
digitalWrite(LED_PIN, HIGH);
delay((NOTE_MULTIPLIER * note) / 2);
digitalWrite(LED_PIN, LOW);
delay((NOTE_MULTIPLIER * note) / 2);
} else if (note < 0) {
digitalWrite(LED_PIN, LOW);
delay(NOTE_MULTIPLIER * (-1 * note));
}
}
void playMeasure(int measure[]) {
for (int i = 0;; i++) {
int note = measure[i];
if (note == 0) {
return;
}
playNote(note);
}
}
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// int testMeasure[] = {2, 2, 2, 2, 2, -2, -2, -2, 0};
// playMeasure(testMeasure);
playMeasure(measure0);
playMeasure(measure1);
playMeasure(measure2);
playMeasure(measure3);
playMeasure(measure4);
playMeasure(measure5);
playMeasure(measure6);
playMeasure(measure7);
playMeasure(measure8);
playMeasure(measurePop);
}