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

How to do it...

Let's perform the following steps:

  1. Run the following lines of code in the REPL. You should hear five separate tones playing for 0.2 seconds each. The sounds will start at a lower pitch and gradually get higher and higher. As each tone plays, the frequency of the tone will be printed to the output in the REPL:
>>> from adafruit_circuitplayground.express import cpx >>> for i in range(500, 1000, 100): ... print(i) ... cpx.play_tone(i, 0.2)
...     
...     
... 
500
600
700
800
900
>>> 
  1. Use the following code to play three different tones. The tones will increase in pitch and will also increase in terms of duration of the playback:
>>> from adafruit_circuitplayground.express import cpx
>>> for i in range(200, 500, 100):
...     print(i)
...     cpx.play_tone(i, i/1000)
...     
...     
... 
200
300
400
>>>