// Define the pins for the LEDs
const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
// Number of LEDs
const int numLeds = sizeof(ledPins) / sizeof(ledPins[0]);
// Define the rhythm of the song in milliseconds
// Based on the rhythm of "We Wish You a Merry Christmas and a Happy New Year"
// This is a simplified version and may not perfectly match the actual song
const int rhythm[] = {
500, 500, 500, 500, 1000, // "We wish you a"
500, 500, 500, 500, 1000, // "Merry Christmas"
500, 500, 500, 500, 1000, // "We wish you a"
500, 500, 500, 500, 1000, // "Merry Christmas"
500, 500, 500, 500, 1000, // "We wish you a"
500, 500, 500, 500, 1000, // "Merry Christmas"
500, 500, 500, 500, 1000, // "And a happy"
500, 500, 500, 500, 2000 // "New Year"
};
// Number of rhythm elements
const int rhythmLength = sizeof(rhythm) / sizeof(rhythm[0]);
void setup() {
// Initialize the LED pins as outputs
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Play the rhythm of the song using the LEDs
for (int i = 0; i < rhythmLength; i++) {
// Turn on the current LED
digitalWrite(ledPins[i % numLeds], HIGH);
// Wait according to the rhythm
delay(rhythm[i]);
// Turn off the current LED
digitalWrite(ledPins[i % numLeds], LOW);
}
// Wait for a short while before repeating the sequence
delay(1000);
}