pxt-calliope/docs/reference/music/play-tone.md

32 lines
847 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# Play Tone
Play a musical tone through pin ``P0`` of the micro:bit for as long as you say.
2016-03-26 00:47:20 +01:00
## Simulator
This function only works on the micro:bit and in some browsers.
2016-03-26 00:47:20 +01:00
```sig
music.playTone(440, 120)
```
### Parameters
* `Hz` is the [Number](/reference/types/number) of Hertz (the frequency, how high or low the tone is).
* `ms` is the [Number](/reference/types/number) of milliseconds that the tone lasts.
2016-03-26 00:47:20 +01:00
## Example
This example stores the musical note C in the variable `freq`.
Next, it plays that note for 1000 milliseconds (one second).
2016-03-26 00:47:20 +01:00
```blocks
let freq = music.noteFrequency(Note.C)
music.playTone(freq, 1000)
```
### See also
2016-04-13 17:27:45 +02:00
[rest](/reference/music/rest), [ring tone](/reference/music/ring-tone) , [tempo](/reference/music/tempo), [set tempo](/reference/music/set-tempo), [change tempo by](/reference/music/change-tempo-by)
2016-03-26 00:47:20 +01:00