附录 - 4
MicroPython lets you make tones that are not musical notes. For example, here’s how to create a Police siren effect:
Notice：The music.pitch method is used in this instance. It expects a frequency. For example, the frequency of 440 is the same as a concert A used to tune a symphony orchestra.
In the example above the range function is used to generate ranges of numeric values. These numbers are used to define the pitch of the tone. The three arguments for the range function are the start value, end value and step size. Therefore, the first use of range is saying, in English, “create a range of numbers between 880 and 1760 in steps of 8”. The second use of range is saying, “create a range of values between 1760 and 880 in steps of -8”. This is how we get a range of frequencies that go up and down in pitch like a siren. For each frequency in the specified range of frequencies, the pitch of that frequency is played for 3 milliseconds.