set Audio Pin

Set the pin (P0, P1, P2) that is used to play music and generate tones.


micro:bit V2 speaker

With the micro:bit V2 hardware, the built-in speaker will play (mirror) the same tones and music sent to the audio pin.


  • name: the pin to set for audio output: P0, P1, or P2.


Play a tone for the “A4” note at pin P0 for 1 second.

let frequency = 440
let duration = 1000
pins.analogPitch(frequency, duration)

See also

micro:bit pins, analog set pitch pin