Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Buzzer Melody"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2023-12-19 21:57:19
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* play melody of jingle bells one time. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <ezBuzzer.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t buzzer_Pin = 3; // Replace with the actual pin number
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- ezBuzzer buzzer(buzzer_Pin); // Instantiate ezBuzzer object with the buzzer pin number
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(buzzer_Pin, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- /****** SYSTEM REQUIREMENTS *****/
- // SYSTEM REQUIREMENT 1: play melody of jingle bells one time
- int melody[] = {
- NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_G4,
- NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
- NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
- NOTE_D4, NOTE_G4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
- NOTE_G4, NOTE_C4, NOTE_D4, NOTE_E4,
- NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4,
- NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
- NOTE_D4, NOTE_G4
- };
- int noteDurations[] = {
- 8, 8, 4, 8, 8, 4, 8, 8,
- 8, 8, 4, 8, 8, 4, 8, 8,
- 8, 8, 4, 8, 8, 4, 8, 8,
- 4, 4, 8, 8, 8, 8, 4, 4,
- 8, 8, 8, 8,
- 8, 8, 4, 8, 8, 4, 8, 8, 8,
- 8, 4, 4, 8,
- 4, 4
- };
- static bool playMelody = true; // Flag to play melody once
- if (playMelody)
- {
- buzzer.playMelody(melody, noteDurations, sizeof(melody) / sizeof(int));
- playMelody = false; // Reset the flag to prevent playing melody repeatedly
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement