2016-03-26 00:47:20 +01:00
|
|
|
# Play Tone
|
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
Play a musical tone through pin ``P0`` of the @boardname@ for as long as you say.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
## Simulator
|
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
This function only works on the @boardname@ and in some browsers.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
music.playTone(440, 120)
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
2016-07-18 19:39:41 +02:00
|
|
|
* ``frequency`` is the [number](/reference/types/number) of Hertz (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
|
|
|
|
|
2016-05-23 20:50:08 +02:00
|
|
|
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)
|
|
|
|
```
|
|
|
|
|
2016-11-29 17:59:54 +01:00
|
|
|
|
|
|
|
### Using other pins
|
|
|
|
|
|
|
|
Use [analogSetPitchPin](/pins/analog-set-pitch-pin) to change that pin used to generate music.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
pins.analogSetPitchPin(AnalogPin.P1);
|
|
|
|
```
|
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
### See also
|
|
|
|
|
2016-06-15 14:09:40 +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
|
|
|
|