#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Define hardware type, size, and output pins
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 120 // Change this if you have more matrices
#define CS_PIN 10
#define DATA_PIN 11
#define CLK_PIN 13
// Create an instance of the MD_Parola class
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
const int buzzerPin = 12; // Connect the buzzer to pin 8
// Define the notes for "Happy Birthday"
const int melody[] = {
262, 262, 294, 262, 349, 330, // Happy Birthday to you
262, 262, 294, 262, 392, 349, // Happy Birthday to you
262, 262, 587, 440, 349, 330, 294, // Happy Birthday dear [Name]
466, 466, 440, 349, 392, 349 // Happy Birthday to you
};
// Define the note durations
const int noteDurations[] = {
4, 4, 4, 4, 4, 4, // Happy Birthday to you
4, 4, 4, 4, 4, 4, // Happy Birthday to you
4, 4, 4, 4, 4, 4, 4, // Happy Birthday dear [Name]
4, 4, 4, 4, 4, 4 // Happy Birthday to you
};
void setup() {
// Initialize the display
myDisplay.begin();
pinMode(buzzerPin, OUTPUT);
myDisplay.setIntensity(10); // Set brightness (0-15)
myDisplay.displayClear(); // Clear the display
myDisplay.displayText("Happy Birthday", PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}
void loop() {
// Animate the display
if (myDisplay.displayAnimate()) {
myDisplay.displayReset();
}
// Play the melody
playMelody();
}
void playMelody() {
for (int thisNote = 0; thisNote < sizeof(melody) / sizeof(melody[0]); thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(buzzerPin, melody[thisNote], noteDuration);
// Pause for the note's duration plus a bit of silence
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// Stop the tone playing
noTone(buzzerPin);
}
}