MicroPython Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

In the first block of code, the for loop will iterate over the frequency value, starting from 500 and raising the value in increments of 100 to end at 900. This range and these steps will be easily audible to the human ear. In each iteration, the frequency to be played will be printed out and then played using the play_tone method. Only the frequency of the sound changes in each iteration; they will all play for 200 milliseconds.

In the second block of code, the for loop will iterate over a lower sound pitch and through fewer tones. For each iteration, the frequency and duration of the tone increases. The frequency will be the exact value of the i variable, while the duration will be the value of i in terms of milliseconds. Since the play_tone method is expecting the value in seconds, we must divide it by 1,000.