Assignment: Input / Output Coincidence Lab Assignment
Collaborators: schluchter, mcozzi
Description:
created a prototype that allows you to trigger the Teenage Mutant Ninja Turtle (TMNT) theme song when you shine a light on the photocell, and control the playback speed by spinning the bow-staff.
Components Used:
- Light Emitting Diode (LED)--green
- 10k resistor
- Arduino board
- Bread board
- Wires
- Photocell
- Piezo speaker
- Flashlight
- Electrical tape
- Some cardboard
- Pencil (a.k.a. - bo-staff)
- Donatello background printout
- Donatello action figure
Arduino Code:
#include <Tone.h>
Tone tmntsong;
int potPin = 0;
int lightPin = 5;
int speakerPin = 7;
int val = 0;
int lightval = 0;
float factor = 1.00;
int notes[] = {
NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_DS5, NOTE_F5, NOTE_DS5, NOTE_F5, NOTE_DS5, NOTE_F5, NOTE_DS5, NOTE_F5, NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5, NOTE_AS4, NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5
};
int durations[] = {
100, 100, 100, 100, 100, 100, 300, 100, 100, 100, 100, 100, 100, 100, 300, 100, 100, 100, 100, 100, 100, 100, 300, 100, 90, 90, 90, 90, 200, 100, 90, 90, 100
};
int pauses[] = {
100, 100, 100, 100, 100, 0, 0, 100, 100, 100, 100, 100, 100, 0, 0, 100, 100, 100, 100, 100, 100, 0, 0, 100, 10, 10, 10, 10, 0, 300, 10, 10, 0
};
void setup() {
Serial.begin(9600);
tmntsong.begin(speakerPin);
}
float factor1() { //This controls the speed factor of the song ranging between 0-2. 0= super fast, 1 = normal, 2 = slow
val = analogRead(potPin);
factor = val / 512.0;
Serial.println(val);
Serial.println(factor);
return factor;
}
void playnote(int note, int duration) {
factor = factor1();
tmntsong.play(note);
delay(duration*factor);
tmntsong.stop();
}
void pause(int duration) {
factor = factor1();
delay(duration*factor);
}
void playSong() {
for (int thisNote = 0; thisNote < 33; thisNote ++) {
// play the next note:
playnote(notes[thisNote], durations[thisNote]);
pause(pauses[thisNote]);
}
// hold before repeating:
delay(1000);
}
void loop() {
lightval = analogRead(lightPin); //read the value from the photocell
if (lightval > 400) {
playSong();
// play TMNT song
}
}
-----------------------------------------------------
Here's a video of it working: