pxt-calliope/docs/reference/music/play-tone.md
Sam El-Husseini e3975e65e5 pxt-microbit Accessibility PR ()
* Accessibility changes
2017-09-07 13:42:08 -07:00

1009 B

Play Tone

Play a musical tone through pin P0 of the @boardname@ for as long as you say.

~ hint

This function only works on the @boardname@ and in some browsers.

~

music.playTone(440, 120)

Parameters

  • frequency is the number of Hertz (how high or low the tone is).
  • ms is the number of milliseconds that the tone lasts

Example

This example stores the musical note C in the variable freq. Next, it plays that note for 1000 milliseconds (one second).

let freq = music.noteFrequency(Note.C)
music.playTone(freq, 1000)

Using other pins

Use analogSetPitchPin to change that pin used to generate music.

pins.analogSetPitchPin(AnalogPin.P1);

See also

rest, ring tone , tempo, set tempo, change tempo by