Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
Description
Philip Glass is one of my favorite composers and musicians. I knew I wanted to design an artifact that involved sound, and decided to create a glass that when picked up would play a song in the style of Philip Glass' repetitive and slowly modulating pieces. I composed the song on my trumpet at first and transposed it as best I could.
So this is my Ode to Philip::: Glass.
Components Used
- 1 Photocell
- 1 Piezo Speaker
- 1 Resistor
- Arduino Board
- Breadboard
- Wire
- Glass
- Electrical Tape
Arduino Code
/* Ode to Philip::: Glass
* -----------
*
* This program is designed to work play a melody similar to that of
* composer Philip Glass. Whenever the light sensor is activated
* the melody is played once through.
*
*
* The calculation of the tones is made following the mathematical
* operation:
*
* timeHigh = 1/(2 * toneFrequency) = period / 2
*
* where the different tones are described as in the table:
*
* note frequency period PW (timeHigh)
* c 261 Hz 3830 1915
* d 294 Hz 3400 1700
* e 329 Hz 3038 1519
* f 349 Hz 2864 1432
* f# 369 Hz 1353
* g 392 Hz 2550 1275
* a 440 Hz 2272 1136
* b 493 Hz 2028 1014
* C 523 Hz 1912 956
*
*
*/
int sensorPin = 0;
int speakerOut = 7;
int val = 0;
byte names[] = {'c', 'd', 'e', 'f','F', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1353, 1275, 1136, 1014, 956};
byte melody[] = "3g3f3g3f3g3f3g3f3g3F3g3F3g3F3g3F3g3f3g3f3g3f3g3f3g3F3g3F3g3F3g3F3g3f3g3f3g3f3g3f3g3F3g3F3g3F3g3F3g3b3g3b3g3b3g3b3g3f3g3f3g3f3g3f3g3b3g3b3g3b3g3b3g3f3g3f3g3f3g3f3g3b3g3b3g3b3g3b3g3f3g3f3g3f3g3f";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
// 10 20 30 40 50 60 70 80 90
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 96;
int statePin = LOW;
void setup() {
pinMode(speakerOut, OUTPUT);
Serial.begin(9600);
Serial.
println("ready");
}
void loop() {
digitalWrite(speakerOut, LOW);
val = analogRead(sensorPin);
val = val*2;
Serial.println(val);
if (val>350)
eft: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 11px; font-family: inherit; vertical-align: baseline; padding: 0px; border: 0px initial initial;">
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
}
}
}
}
Video