Skip to content

Instantly share code, notes, and snippets.

@mbrav
Created September 16, 2016 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbrav/fd56ff01b985699b3825df33c41ff7b4 to your computer and use it in GitHub Desktop.
Save mbrav/fd56ff01b985699b3825df33c41ff7b4 to your computer and use it in GitHub Desktop.
A broken cathode tube display coming back to life in a new digital form — a material manifestation of Beethoven’s “Ode to Joy”.
// Hummin
// A broken cathode tube display coming back to life in a
// new digital form — a material manifestation of Beethoven’s “Ode to Joy”.
// Assembly: https://bfadtdeviceart.wordpress.com/2016/09/06/hummin/
// Created by Michael Braverman
// September 3, 2016
int cathodePin = 7;
int blinkPin = 13;
int speakerPin = 8;
int length = 62; // the number of notes
char notes[] = "eefggfedccdeeddeefggfedccdedccddecdefecdefedcdgeefggfedccdedcc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2};
int tempo = 100;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i +=tone * 2) {
digitalWrite(speakerPin, HIGH);
digitalWrite(blinkPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
digitalWrite(blinkPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b'};
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014};
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
pinMode(cathodePin, OUTPUT);
pinMode(blinkPin, OUTPUT);
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] *tempo); //rest
} else {
playNote(notes[i], beats[i] *tempo);
Serial.println(notes[i]);
}
// pause between notes
delay((tempo /3)*2);
digitalWrite(cathodePin, HIGH);
delay(tempo /3);
digitalWrite(cathodePin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment