Advertisement
pleasedontcode

"Buzzer Melody" rev_17

Dec 19th, 2023
113
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 22:23:21
  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 alarm_ActiveBuzzer_output_PIN_D2 = 2;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. ezBuzzer buzzer(alarm_ActiveBuzzer_output_PIN_D2);
  36.  
  37. void setup(void)
  38. {
  39.     // put your setup code here, to run once:
  40.     pinMode(alarm_ActiveBuzzer_output_PIN_D2, OUTPUT);
  41. }
  42.  
  43. void loop(void)
  44. {
  45.     // put your main code here, to run repeatedly:
  46.  
  47.     // System Requirement 1: Play melody of jingle bells one time
  48.     int melody[] = {
  49.         NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_G4,
  50.         NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  51.         NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
  52.         NOTE_D4, NOTE_G4
  53.     };
  54.  
  55.     int noteDurations[] = {
  56.         8, 8, 4, 8, 8, 4, 8, 8, 8, 8, 2, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 8, 8, 4, 4
  57.     };
  58.  
  59.     int length = sizeof(melody) / sizeof(int);
  60.     buzzer.playMelody(melody, noteDurations, length);
  61.  
  62.     // Delay for 5 seconds before playing the melody again
  63.     delay(5000);
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement