#include <LedControl.h>
#include "pitches.h"
LedControl lc = LedControl(12, 11, 10, 1); // Pins for the MAX7219
int speakerPin = 9; // Pin for the active buzzer
int melody[] = {
NOTE_E5, NOTE_E5, 0, NOTE_E5,
0, NOTE_C5, NOTE_E5, 0,
NOTE_G5, 0, 0, 0,
NOTE_G4, 0, 0, 0,
// ... (melody continues)
NOTE_E5, NOTE_E5, 0, NOTE_E5,
0, NOTE_C5, NOTE_E5, 0,
NOTE_G5, 0, 0, 0,
NOTE_G4, 0, 0, 0,
};
int noteDurations[] = {
8, 8, 4, 8,
4, 4, 8, 4,
4, 4, 4, 4,
4, 4, 4, 4,
// ... (note durations continue)
8, 8, 4, 8,
4, 4, 8, 4,
4, 4, 4, 4,
4, 4, 4, 4,
};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
pinMode(speakerPin, OUTPUT);
}
void loop() {
displayHeart();
playMelody();
}
void displayHeart() {
// Your code to display the heart shape on the MAX7219
// Refer to the MAX7219 library documentation for specific commands
}
void playMelody() {
for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) {
int duration = 1000 / noteDurations[i];
tone(speakerPin, melody[i], duration);
delay(duration + 50); // Add a small delay between notes
noTone(speakerPin);
delay(50); // Add a pause between notes
}
}