Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
Collaborators: Ljuba Miljkovic
The purpose of this lab was to:
Ljuba and I decided to make a flute that is powered by light (instead of wind). By pressing the four different photocells in various combinations, different notes are played (an entire octave has been coded), and different LED lights are illuminated.
We created a circuit with four input sensors (photocells). By covering up the sensors, or "pressing the keys," the Piezo speaker can be manipulated to play a scale. LED lights concurrently change colors as well, and are diffused using an opaque cylinder in the shape of a flute (sort of).
int speakerPin = 7; //Speaker Mapping int photocell_C = 0; // Photocell Mapped to C int photocell_D = 1; // Photocell Mapped to D int photocell_E = 2; // Photocell Mapped to E int photocell_F = 3; // Photocell Mapped to F int greenPin = 9; // select the pin for the LED 9 int redPin = 10; // select the pin for the LED 10 int bluePin = 11; // select the pin for the LED 11 //threshold for turning notes on and off. Though we experimented with various //percentage change calculations, the photocells are so sensitive and varied //that this hardcoding strategy works best in this case: int C_MIN = 200; int D_MIN = 400; int E_MIN = 10; int F_MIN = 150; //http://www.home.agilent.com/agilent/editorial.jspx?cc=US&lc=eng&ckey=431980&nid=-536902257.793368.02&id=431980 int C = 956; int D = 851; int E = 758; int F = 716; int G = 638; int A = 568; int B = 506; int C_HIGH = 478; //238; void setup() { pinMode(speakerPin, OUTPUT); beginSerial(9600); Serial.println("ready"); } void loop() { Serial.print("C: "); Serial.print(analogRead(photocell_C)); Serial.print(" D: "); Serial.print(analogRead(photocell_D)); Serial.print(" E: "); Serial.print(analogRead(photocell_E)); Serial.print(" F: "); Serial.println(analogRead(photocell_F)); if(analogRead(photocell_C) < C_MIN && analogRead(photocell_D) < D_MIN) { playLight(bluePin); playNote(G); } else if(analogRead(photocell_C) < C_MIN && analogRead(photocell_E) < E_MIN) { playLight(greenPin); playNote(A); } else if(analogRead(photocell_C) < C_MIN && analogRead(photocell_F) < F_MIN) { playLight(redPin); playNote(B); } else if(analogRead(photocell_D) < D_MIN && analogRead(photocell_E) < E_MIN) { playLight(bluePin); playNote(C_HIGH); } else if(analogRead(photocell_C) < C_MIN) { playLight(greenPin); playNote(C); } else if(analogRead(photocell_D) < D_MIN) { playLight(redPin); playNote(D); } else if(analogRead(photocell_E) < E_MIN) { playLight(bluePin); playNote(E); } else if(analogRead(photocell_F) < F_MIN) { playLight(greenPin); playNote(F); } else { analogWrite(greenPin, 0); analogWrite(redPin, 0); analogWrite(bluePin, 0); } } void playLight(int thePin) { analogWrite(greenPin, 0); analogWrite(redPin, 0); analogWrite(bluePin, 0); analogWrite(thePin, 255); } void playNote(int theNote) { for( int i=0; i<200; i++ ) { digitalWrite(speakerPin, HIGH); delayMicroseconds(theNote); digitalWrite(speakerPin, LOW); delayMicroseconds(theNote); } }