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.
onBoardEvent(buttonL, "press", function(event) {
buzzer.note("C4", 100);
});
onBoardEvent(buttonR, "press", function(event) {
buzzer.note("D3", 100);
});
//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);
});
buzzer.note(note, duration)
| Name | Type | Required? | Description |
|---|---|---|---|
| note | string | The type of note that will be played and it's associated octave (A4, C3, etc. ). | |
| duration | number | How long the note should play for in milliseconds. |
Found a bug in the documentation? Let us know at documentation@code.org