play Tone

Play a musical tone on the speaker for some amount of time.

music.playTone(Note.C, 10)

Simulator: ||music:play tone|| works on the Adafruit Circuit Playground Express. It might not work in the simulator on every browser.

Parameters

  • frequency is the number of Hertz (how high or low the tone is, also known as pitch).
  • ms is the number of milliseconds (one-thousandth of a second) that the tone lasts for.

Special handling of values

  • If frequency is less or equal to zero, the sound is stopped.
  • If ms is negative or zero, the sound is not stopped and will keep beeping.

Example

Store the musical note ‘C’ in the variable freq and play that note for 1000 milliseconds (one second).

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

See also

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

music