Assignment: Input / Output Coincidence Lab Assignment
Collaborators:
We can use the potentiometer to control the volume of the piezo speaker even without reading the input into the Arduino board. A glass doorknob (connected awkwardly to the potentiometer with tissue) allows the user to control the single sound coming out of the speaker. But the doorknob also contains an LED, the brightness of which varies with the volume (again, with no logic from the Arduino board), so that the user can immediately get feedback on the change in volume and see at a glance what the current volume is.
We add a resistor in parallel with the output to light and speaker in order to change the pot to an approximation of a log plot (this should make its rotation control the sound in a way that seems more natural to us). Note that we use the output line of the potentiometer to control the volume: this will let us turn the speaker all the way off and all the way up, it's not just a variable resistor.
See this webpage for more information on these uses of potentiometers.
Because so much of the logic is handled by the circuits, the code is extremely simple.
//sound and light
//simplified
int speakerOut = 7;
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
boolean DEBUG = false;
void setup() {
pinMode(speakerOut, OUTPUT);
}
void loop() {
playNote();
}
void playNote() {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[0]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[0]);
}