Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int buzzerPin = 8;
- const int ledPin1 = 12;
- const int ledPin2 = 13;
- int counter = 0;
- unsigned long previousMillis = 0;
- unsigned long noteDuration = 0;
- float tempoFactor = 1.75; // Adjust the tempo factor as needed
- void setup()
- {
- pinMode(buzzerPin, OUTPUT);
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- }
- void loop()
- {
- // Play first section
- firstSectionSG();
- // Play second section
- // secondSectionSG();
- // Play third section
- // thirdSectionSG();
- // Play fourth section
- // fourthSectionSG();
- // Play fifth section
- // fifthSectionSG();
- }
- void beep(int note, int duration)
- {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= noteDuration)
- {
- tone(buzzerPin, note, duration);
- previousMillis = currentMillis;
- noteDuration = duration;
- if (counter % 2 == 0)
- {
- digitalWrite(ledPin1, HIGH);
- delay(duration);
- digitalWrite(ledPin1, LOW);
- }
- else
- {
- digitalWrite(ledPin2, HIGH);
- delay(duration);
- digitalWrite(ledPin2, LOW);
- }
- noTone(buzzerPin);
- delay(50);
- counter++;
- }
- }
- // Implement the sections using the same approach as beep() function
- void firstSectionSG()
- {
- beep(261, (int)(250 * tempoFactor));
- beep(391, (int)(750 * tempoFactor));
- beep(391, (int)(250 * tempoFactor));
- beep(523, (int)(250 * tempoFactor));
- beep(466, (int)(500 * tempoFactor));
- beep(415, (int)(125 * tempoFactor));
- beep(391, (int)(125 * tempoFactor));
- beep(415, (int)(125 * tempoFactor));
- beep(391, (int)(750 * tempoFactor));
- delay((int)(125 * tempoFactor)); // Eighth note rest
- beep(391, (int)(62 * tempoFactor));
- beep(440, (int)(62 * tempoFactor));
- beep(466, (int)(62 * tempoFactor));
- beep(493, (int)(62 * tempoFactor));
- beep(523, (int)(125 * tempoFactor));
- delay((int)(125 * tempoFactor)); // Eighth note rest
- delay((int)(250 * tempoFactor)); // Quarter note rest
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement