Advertisement
pleasedontcode

"Buzzer Melody" rev_15

Dec 19th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Buzzer Melody"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-19 21:57:19
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* play melody of jingle bells one time. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <ezBuzzer.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  32. const uint8_t buzzer_Pin = 3; // Replace with the actual pin number
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. ezBuzzer buzzer(buzzer_Pin); // Instantiate ezBuzzer object with the buzzer pin number
  36.  
  37. void setup(void)
  38. {
  39.   // put your setup code here, to run once:
  40.   pinMode(buzzer_Pin, OUTPUT);
  41. }
  42.  
  43. void loop(void)
  44. {
  45.   // put your main code here, to run repeatedly:
  46.  
  47.   /****** SYSTEM REQUIREMENTS *****/
  48.  
  49.   // SYSTEM REQUIREMENT 1: play melody of jingle bells one time
  50.   int melody[] = {
  51.     NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_G4,
  52.     NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  53.     NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
  54.     NOTE_D4, NOTE_G4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
  55.     NOTE_G4, NOTE_C4, NOTE_D4, NOTE_E4,
  56.     NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
  57.     NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
  58.     NOTE_D4, NOTE_G4
  59.   };
  60.  
  61.   int noteDurations[] = {
  62.     8, 8, 4, 8, 8, 4, 8, 8,
  63.     8, 8, 4, 8, 8, 4, 8, 8,
  64.     8, 8, 4, 8, 8, 4, 8, 8,
  65.     4, 4, 8, 8, 8, 8, 4, 4,
  66.     8, 8, 8, 8,
  67.     8, 8, 4, 8, 8, 4, 8, 8, 8,
  68.     8, 4, 4, 8,
  69.     4, 4
  70.   };
  71.  
  72.   static bool playMelody = true; // Flag to play melody once
  73.  
  74.   if (playMelody)
  75.   {
  76.     buzzer.playMelody(melody, noteDurations, sizeof(melody) / sizeof(int));
  77.     playMelody = false; // Reset the flag to prevent playing melody repeatedly
  78.   }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement