App Lab Documentation

buzzer.playNotes

Category:Circuit

Plays an array of notes one after the other.

buzzer.playNotes() is a method of the buzzer that plays an array of notes one after the other at a given tempo. All of the notes are played as a whole note; if you want to change how long a particular note is played for, you can use the buzzer.playSong() method.

This method accepts two parameters: a one-dimensional array full of notes, and a tempo to play them at. Tempo is an optional parameter, but if left undefined defaults to 120bpm.

Syntax

buzzer.playNotes(notes, tempo)

Parameters

NameTypeRequired?Description
notesList

An array of notes (such as ['C4', 'D4', 'E4']). Each note will be played in sequence from first (index 0) to last (index notes.length - 1).

tempoNumber

The tempo determines the speed at which the list of notes will be played, in beats per minute (or bpm). If a tempo is not included, notes will play at a default tempo of 120 bpm

Tips

  • To add a pause in between notes, add a new item that contains null. null is a way to represent emptiness in computer science, and the buzzer.playNotes() method will read that as "Play nothing for the duration of a whole note".

Found a bug in the documentation? Let us know at support@code.org.