pxt-calliope/docs/reference/music/set-play-tone.md
Juri Wolf 5f7a8e5301
Updates for V4 (#197)
* update yotta defaults for 16kb devices

* refactor deprecated blocks

* updates for button events

* update button events

* update refference

* update docs

* update docs

* update button event blocks

* update docs

* update block id
2022-08-10 09:36:19 -07:00

1.0 KiB

Set Play Tone

Replaces the implementation of the music play tone.

music.setPlayTone((frequency: number, duration: number) => {})

Parameters

  • f the replacement function

Example

This example send the frequency and duration over radio and plays it on the remote @boardname@.

input.onButtonEvent(Button.A, input.buttonEventClick(), () => {
    music.playTone(440, 120)
    led.toggle(0, 0)
})
radio.onReceivedNumber(function (receivedNumber) {
    const freq = receivedNumber >> 16;
    const duration = receivedNumber & 0xffff;
    music.playTone(freq, duration);
})
input.onButtonEvent(Button.B, input.buttonEventClick(), () => {
    music.setPlayTone((frequency: number, duration: number) => {
        radio.sendNumber((frequency << 16) | (duration & 0xffff));
    })    
})

See also

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