Advertisement
pleasedontcode

Melody Buzzer rev_01

Jun 6th, 2024
305
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: Melody Buzzer
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-06 17:57:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* play https video on buzzer */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <ezBuzzer.h>  //https://github.com/ArduinoGetStarted/buzzer
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void);
  30.  
  31. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  32. const uint8_t mybuzzer_PassiveBuzzer_Signal_PIN_D2 = 2;
  33.  
  34. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  35. /***** used to store raw data *****/
  36. bool mybuzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
  37.  
  38. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  39. /***** used to store data after characteristic curve transformation *****/
  40. float mybuzzer_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. const int BUZZER_PIN = 3;  // Define the pin for the buzzer
  44. ezBuzzer buzzer(BUZZER_PIN);  // Initialize the ezBuzzer object
  45.  
  46. int melody[] = {
  47.   NOTE_E5, NOTE_E5, NOTE_E5,
  48.   NOTE_E5, NOTE_E5, NOTE_E5,
  49.   NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,
  50.   NOTE_E5,
  51.   NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
  52.   NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,
  53.   NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,
  54.   NOTE_D5, NOTE_G5
  55. };
  56.  
  57. int noteDurations[] = {
  58.   8, 8, 4,
  59.   8, 8, 4,
  60.   8, 8, 8, 8,
  61.   2,
  62.   8, 8, 8, 8,
  63.   8, 8, 8, 16, 16,
  64.   8, 8, 8, 8,
  65.   4, 4
  66. };
  67.  
  68. int noteLength;
  69.  
  70. void setup(void)
  71. {
  72.   // put your setup code here, to run once:
  73.   Serial.begin(9600);
  74.   pinMode(mybuzzer_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
  75.   noteLength = sizeof(noteDurations) / sizeof(int);
  76. }
  77.  
  78. void loop(void)
  79. {
  80.   // put your main code here, to run repeatedly:
  81.   buzzer.loop();  // Update the buzzer state
  82.  
  83.   if (buzzer.getState() == BUZZER_IDLE) {
  84.     buzzer.playMelody(melody, noteDurations, noteLength);  // Play the melody when the buzzer is idle
  85.   }
  86.  
  87.   updateOutputs();  // Refresh output data
  88. }
  89.  
  90. void updateOutputs()
  91. {
  92.   digitalWrite(mybuzzer_PassiveBuzzer_Signal_PIN_D2, mybuzzer_PassiveBuzzer_Signal_PIN_D2_rawData);
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement