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: "Melody Display"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-01-05 17:55:14
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* plays crazy story by king von */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h> // Ensure to include the Arduino library for tone and digitalWrite functions
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t buzz_ActiveBuzzer_output_PIN_D2 = 2;
- #define BUZZER_PIN 8 // Using a different pin for the buzzer
- #define LED_PIN 13 // Define LED pin
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool buzz_ActiveBuzzer_output_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float buzz_ActiveBuzzer_output_PIN_D2_phyData = 0.0;
- // Define the notes and durations for the melody
- int melody[] = {NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};
- int noteDurations[] = {4, 8, 8, 4, 4, 4, 4, 4};
- // Define the lyrics for the story
- String lyrics[] = {"I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field",
- "I was in the trenches, yeah, I was in the field"};
- // Define the tempo for the melody
- int tempo = 120;
- // Define the current note and duration index
- int noteIndex = 0;
- int durationIndex = 0;
- // Define the current lyric index
- int lyricIndex = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(buzz_ActiveBuzzer_output_PIN_D2, OUTPUT);
- pinMode(BUZZER_PIN, OUTPUT); // Set the buzzer pin as output
- pinMode(LED_PIN, OUTPUT); // Set the LED pin as output
- Serial.begin(9600); // Initialize serial communication for printing lyrics
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // Calculate the duration of the current note
- int noteDuration = 1000 / noteDurations[durationIndex];
- // Play the current note on the buzzer
- tone(BUZZER_PIN, melody[noteIndex], noteDuration);
- // Turn on the LED to indicate the current lyric
- digitalWrite(LED_PIN, HIGH);
- // Print the current lyric to the serial monitor
- Serial.println(lyrics[lyricIndex]);
- // Wait for the duration of the note
- delay(noteDuration);
- // Turn off the LED
- digitalWrite(LED_PIN, LOW);
- // Stop the buzzer
- noTone(BUZZER_PIN);
- // Increase the note and duration index
- noteIndex++;
- durationIndex++;
- // Check if the end of the melody has been reached
- if (noteIndex >= sizeof(melody) / sizeof(int)) {
- // Reset the note and duration index
- noteIndex = 0;
- durationIndex = 0;
- }
- // Check if the end of the lyrics has been reached
- if (lyricIndex >= sizeof(lyrics) / sizeof(String)) {
- // Reset the lyric index
- lyricIndex = 0;
- }
- // Wait for the duration of a quarter note
- delay(60000 / tempo);
- }
- void updateOutputs()
- {
- digitalWrite(buzz_ActiveBuzzer_output_PIN_D2, buzz_ActiveBuzzer_output_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement