username32390394054

checkBuzzer

Jul 23rd, 2025
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | Source Code | 0 0
  1. const int buzzerPin = 11;  // Pin connected to the speaker
  2.  
  3. void buzz(uint16_t repeat = 2) {
  4.   const int melody[] = { 1000, 1200, 1000, 1200 };  // Frequencies in Hz
  5.   const int duration = 150; // Duration of each tone in ms
  6.  
  7.   for (uint16_t r = 0; r < repeat; r++) {
  8.     for (int i = 0; i < sizeof(melody) / sizeof(int); i++) {
  9.       tone(buzzerPin, melody[i]);
  10.       delay(duration);
  11.       noTone(buzzerPin);
  12.       delay(50); // Short pause between tones
  13.     }
  14.     delay(200); // Pause between repetitions
  15.   }
  16. }
  17.  
  18.  
  19. void setup()  {
  20.   pinMode(buzzerPin, OUTPUT);
  21.   buzz(10);  // Play the melody 10 times on startup
  22. }
  23.  
  24. void loop() {
  25.   // Nothing here, we only test in setup()
  26. }
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment