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.
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); });
buzzer.frequency(frequency, duration)
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. |
Found a bug in the documentation? Let us know at documentation@code.org