Print

JavaJava: Lesson 5 – Sound with the Finch

Resources

Resources available for teachers.   

The last Finch output is the buzzer. You can you the buzz() method to play a tone on the Finch’s internal buzzer. This method requires two parameters. The first is the frequency of the sound; keep in mind that humans can only hear sounds in the range of 20 to 20,000 Hz. The second parameter is the duration of the sound in milliseconds. This method will start the buzzer and then immediately move on to the next line of code.

Exercise 1:

Try out the code shown below. The robot should buzz while moving forward for one second.

Exercise 2:

Write a program to make the Finch move forward, then back. When the Finch is moving forward, it should make a low-pitched buzz. When the Finch is moving back, it should make a high-pitched buzz.

If you want the Finch to play tones without moving, you can separate the tones using the sleep() method. This method pauses the program for the number of milliseconds. For example, the code below plays two tones. Without the sleep() commands, these tones would overlap. The number of milliseconds for each sleep() command is slightly longer than the number of milliseconds for each buzz so that the tones will be slightly separated.

Exercise 3:

Write a program to make the Finch play a short song. Choose a song from this website and make the Finch play your song using its buzzer!

Note:

In addition to buzz(), there is also a similar Finch method called playTone() that will play a sound using your computer speakers instead of the Finch buzzer. The parameters for this method are the same.

Exercise 4:

Practice all of the things you have learned about the Finch! Write a program to make the Finch move in a triangle, pentagon, or other shape. The Finch should buzz as it starts each side of the shape. For an added challenge, make the beak change to a different random color for each side of the shape.

Exercise 5:

Make the Finch dance! Write a script to make the Finch move and change its beak color. Use the buzzer to add sound!