Active Buzzer
In this lesson, you will learn how to generate a sound with an active buzzer.
Last updated
#include "pitches.h"// notes in the melody:
int melody[] = {
NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6
};
int duration = 500; // 500 miliseconds
void setup() { }
void loop() {
for (int thisNote = 0; thisNote < 12; thisNote++) {
// pin12 output the voice, every scale is 0.5 sencond
tone(12, melody[thisNote], duration);
delay(100);
// Output the voice after several minutes
delay(100);
} // restart after two seconds
delay(200);
}