50 likes | 372 Views
living with the lab. piezo speaker circuit. robot whistle challenge. © 2011 LWTL faculty team. living with the lab. wiring and simple programming. the sketch below will create a square wave with a frequency of approximately 2500 Hz . . . human hearing ranges from about 20Hz to 20,000 Hz.
E N D
living with the lab piezo speaker circuit robot whistle challenge © 2011 LWTL faculty team
living with the lab wiring and simple programming the sketch below will create a square wave with a frequency of approximately 2500 Hz . . . human hearing ranges from about 20Hz to 20,000 Hz digital output (pin 13) void setup() { pinMode(13,OUTPUT); } void loop() { int half_period=200; digitalWrite(13,HIGH); delayMicroseconds(half_period); digitalWrite(13,LOW); delayMicroseconds(half_period); }
living with the lab whistling robot challenge With the piezo speaker installed on the breadboard of your robot, write a sketch to cause the speaker to make a whistle (the instructor will tell you what the whistle should sound like). Have the instructor check your whistle when you are satisfied with the sound. If you don’t finish during class, then complete this outside of class, and demonstrate your working program in class next time to the instructor. HINT:You may need to use several “for” loops where the pitch varies within the loops.
living with the lab • example to get you going • The program shown uses a single, repeating “for” loop to create a sound similar to an alarm. • You can use this program as a starting point, but your whistle will sound best with several for loops. initial frequency: void setup() { pinMode(13,OUTPUT); } void loop() { for(int i=1500; i>500; i=i-8) { digitalWrite(13,HIGH); delayMicroseconds(i); digitalWrite(13,LOW); delayMicroseconds(i); } delay(150); } final frequency: 150 ms 150 ms 1000 frequency (Hz) 330 time (s)
living with the lab delay frequency (Hz) your frequency vs. time plot may look more like this time (s)