Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int buzzerPin = 11; // Pin connected to the speaker
- void buzz(uint16_t repeat = 2) {
- const int melody[] = { 1000, 1200, 1000, 1200 }; // Frequencies in Hz
- const int duration = 150; // Duration of each tone in ms
- for (uint16_t r = 0; r < repeat; r++) {
- for (int i = 0; i < sizeof(melody) / sizeof(int); i++) {
- tone(buzzerPin, melody[i]);
- delay(duration);
- noTone(buzzerPin);
- delay(50); // Short pause between tones
- }
- delay(200); // Pause between repetitions
- }
- }
- void setup() {
- pinMode(buzzerPin, OUTPUT);
- buzz(10); // Play the melody 10 times on startup
- }
- void loop() {
- // Nothing here, we only test in setup()
- }
Advertisement
Add Comment
Please, Sign In to add comment