Advertisement
pleasedontcode

"Buzzer Melody" rev_02

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