buzzer.note()

Category:Circuit

Plays specific notes on the buzzer.

Like .frequency(), buzzer.note() plays different tones on the buzzer. However, instead of giving the buzzer a frequency to play, you give it a note and octave ranging from 1-4 (C3, D4, E4, etc). Anything above octave 5 is too high and will not play on the buzzer.

.notes() has a parameter for duration too. Unless the note is given a duration, it will play continuously.

Examples

Circuit Piano

//Piano keys
onEvent("c4", "click", function(event) {
  buzzer.note("C4", 100);
  
});
onEvent("d4", "click", function(event) {
  buzzer.note("D4", 100);
});
onEvent("e4", "click", function(event) {
  buzzer.note("E4", 100);
});
onEvent("f4", "click", function(event) {
  buzzer.note("F4", 100);
});
onEvent("g4", "click", function(event) {
  buzzer.note("G4", 100);
});
onEvent("a4", "click", function(event) {
  buzzer.note("A4", 100);
});
onEvent("b4", "click", function(event) {
  buzzer.note("B4", 100);
});

//Sharp notes
onEvent("c#", "click", function(event) {
  buzzer.note("C#4", 100);
});
onEvent("d#", "click", function(event) {
  buzzer.note("D#4", 100);
});
onEvent("f#", "click", function(event) {
  buzzer.note("F#4", 100);
});
onEvent("g#", "click", function(event) {
  buzzer.note("G#4", 100);
});
onEvent("a#", "click", function(event) {
  buzzer.note("A#4", 100);
});

onBoardEvent(buttonL, "press", function(event) {
  buzzer.note("C4", 100);
  
});

onBoardEvent(buttonR, "press", function(event) {
  buzzer.note("D3", 100);
  
});

Syntax

buzzer.note(note, duration)

Parameters

Name Type Required? Description
duration number How long the note should play for in milliseconds.
note string The type of note that will be played and it's associated octave (A4, C3, etc. ).

Tips

  • All octaves start at a C note and end on a B note. The notes are ordered C, D, E, F, G, A, B.
  • You can play sharp notes with the buzzer with the # sign, but you cannot play flat notes.
  • The full scale of notes that the buzzer can play is: C, C#, D, D#, E, F, F# G, G# A, A# B.

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