The Turtle can play different tones. The playTone(frequency, duration) function is used for this purpose. The first parameter determines the tone frequency in Hz, the second parameter the playback duration in milliseconds. Here are some tone frequencies
Tone | Frequency | Tone | Frequency |
h' | 494 | h'' | 988 | ||
a' | 440 | a'' | 880 | ||
g' | 392 | g'' | 784 | ||
f' | 349 | f'' | 698 | ||
e' | 330 | e'' | 660 | ||
d' | 294 | d'' | 588 | ||
c' | 262 | c'' | 524 | c''' | 1048 |
These frequencies can be calculated. If you start from a fundamental tone (e.g. a' with f = 440 Hz), you obtain the frequency of the following semitone with the factor 1.05946 and the next whole tone with the factor 1.05946 * 1.05946 ≈ 1.122 (e.g. h' = 440 * 1.122 = 494). The frequencies in the table are rounded.
Why these factors? An octave is divided into twelve semitone steps. (ratio c'' : c' = 2 : 1). |
Example 1: Playing a melody
Explanations of the programme code:
Explanations of the programme code:
|