1
SKILL
LEVEL
Ringo Educational Guide Rev04.1 ~ Plum Geek
Chirps, Zips, and Pings! Sound!
void loop(){
PlayChirp(2000, 50);
//start playing a tone at 2000 hertz
delay(1000);
//wait 1 second
PlayChirp(4000, 50);
//start playing a tone at 4000 hertz
delay(1000);
//wait 1 second
OffChirp();
//stop playing tone
delay(2000);
//wait 2 seconds
}
OffChirp();
//turn off chirp the easy way
PlayChirp(0, 50);
//set Frequency to zero. Ringo stops playing tone
PlayChirp(1000, 0);
//set Amplitude to zero. Ringo stops playing tone
PlayChirp(0, 0);
//set Frequency & Amplitude to zero. Ringo stops playing tone
Let’s look at a working example. Try entering the following code into your main
loop()
function and see what happens.
Run the code on Ringo and see (hear?) what happens. You should hear a mid pitch
tone for one second that then transitions to a higher pitch tone for one second, then
you should hear silence for two seconds, then the process should repeat.
The line
PlayChirp(2000, 50);
causes the tone to begin. It should be noted
that Ringo can do other things while a tone is playing. As you already know, the
delay(1000);
causes Ringo to wait for 1000 milliseconds (which is one second)
before executing the next line
PlayChrip(4000, 50);
which causes Ringo to now
begin playing the tone at 4000 hertz.
The
OffChirp();
is important because this is what is required to make Ringo stop
playing a tone. You can also make him stop playing a tone by either setting the
frequency, or the amplitude, or both, to zero.