Song Player

Teach your Finch to sing by writing a class that converts notes to tones to play.  The class should play a song represented by a string. The string should be composed of notes – acceptable characters are A, a, B, b, C, c, D, d, E, e, F, f, G, and g.  You will need to use the Finch’s buzzer to generate the correct musical note for each letter. Be sure to implement appropriate error checking! How will you ensure that the user enters a valid song?

Using the buzzer requires two arguments,frequency and duration.  For duration, you can use 600 ms for lower case characters and 1200 ms for upper case characters (so upper case characters are long notes and lower case are short notes).  For frequency, use the following mapping of characters to frequencies:

Aa – 880

Bb – 988

Cc – 523

Dd – 587

Ee – 659

Ff – 698

Gg - 784  

Here are some songs you might recognize:





Extension: When a note is played, you should also light the Finch’s beak; each note of a different frequency should have a unique color, though notes with the same frequency but different durations (like ‘A’ and ‘a’) can have the same color. 

Note: With Java and Jython, you can use the playTone method to play the song over the computer speakers instead of using the Finch buzzer.

Assignment Category: