Rest

Play no sound (rest) on the speaker or at a sound pin for the amount of time you say.

music.rest(400)

The duration of the rest is set as a number milliseconds. Instead, it’s typical to use a number of beats or a beat fraction for a rest. The ||music:beat|| block is used to convert beats to milliseconds. You can also make a custom rest by setting the rest duration to certain amount of milliseconds.

Simulator

The ||music:rest|| block works on the micro:bit board. It might not work in the simulator on every browser.

Parameters

  • ms is the number of milliseconds for the duration of the rest. A beat value is used instead as the block’s default rest duration. The number of beats is converted to milliseconds for you.

Example

Middle C loop

Continuously play a Middle C tone for 1 beat and rest for 2 beats.

basic.forever(function () {
    music.playTone(262, music.beat(BeatFraction.Whole))
    music.rest(music.beat(BeatFraction.Double))
})

Custom rest time

Continuously play a Middle C note followed by a random rest time.

basic.forever(function () {
    music.playTone(262, music.beat(BeatFraction.Whole))
    music.rest(randint(500, 2000))
})

See also

play tone, ring tone , tempo, set tempo, change tempo by