Tone lab For this lab, I used photoresistors to control the tone of a buzzer. The buzzer makes a barely audible sound because it needs more than 5v of power to be loud. I only can hook the buzzer up to 5v. Below you will find the code, an image of setup, and a video of me using the photoresistors to control a servo in place of the speaker because you cannot hear the speaker in the video. Code: void setup() { Serial.begin(9600); // initialize serial communications } void loop(){ int analogValue = analogRead(A0); // read the analog input Serial.println(analogValue); // print it // get a sensor reading: int sensorReading = analogRead(A0); // map the results from the sensor reading's range // to the desired pitch range: float frequency = map(sensorReading, 200, 900, 100, 1000); // change the pitch, play for 10 ms: tone(8, f...
Comments
Post a Comment