Hardware Reference
In-Depth Information
Each while() loop will continuously call the tone() function at the appro-
priate frequency for as long as the button is held down. The button can be read
within the while() loop evaluation to avoid having to first save the reading to
a temporary value. digitalRead() returns a Boolean “true” whenever a button
input goes high; the value can be evaluated directly by the while() lo op. To
keep your code neater, you don't need to use brackets for the contents of a loop
if the contents are only one line, as in this example. If you have multiple lines,
you must use curly brackets as you have in previous examples.
NOTE Towatchademovideoofthemicropiano,visit www.exploringarduino.com/
content/ch5 .YoucanalsofindthisvideoontheWileywebsiteshownatthebegin-
ningofthischapter.
Summary
In this chapter you learned about the following:
Speakers create a pressure wave that travels through the air and is per-
ceived as sound by your ears.
Changing electric current induces a magnetic field that can be used to
create sound from a speaker.
The tone() function can be used to generate sounds of arbitrary frequen-
cies and durations.
The Arduino programming language supports the use of arrays for iterat-
ing through sequences of data.
Speaker volume can be adjusted using a potentiometer in series with
a speaker.
 
Search WWH ::




Custom Search