buzzer.frequency()

Category:Circuit Playground

Makes the buzzer play at a specific frequency and duration.

buzzer.frequency() determines what tone the buzzer will play, and for how long this tone will play for. This command is more customizable than .note() because you can choose the frequency you want up to around 500hz (About the 4th octave on the musical scale). Any frequency above 500hz cannot play on the buzzer.

buzzer.frequency() has a parameter for duration too. If the duration is not specified, then the tone will play continuously.

Examples

onEvent("low_button", "click", function(event) {
  buzzer.frequency(100, 200);
  
});
onEvent("medium_button", "click", function(event) {
  buzzer.frequency(300, 200);
  
});
onEvent("high_button", "click", function(event) {
  buzzer.frequency(500, 200);
  
});

Syntax

buzzer.frequency(frequency, duration)

Parameters

Name Type Required? Description
frequency number The number deciding the pitch and note of the sound being played.
duration number Length of how long the buzzer will play the frequency for in milliseconds.

Tips

  • Extremely low and high frequencies can come out sounding distorted. The most usable frequencies are in the range of 261-987.
  • The higher the frequency, the higher the tone will sound.

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