#include <LedControl.h>
// Pin definitions for MAX7219
const int DIN_PIN = 11; // Data In (MOSI)
const int CS_PIN = 10; // Chip Select
const int CLK_PIN = 13; // Clock (SCK)
// Number of MAX7219 units
const int NUM_DEVICES = 4;
// Create a LedControl instance
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, NUM_DEVICES);
// Define bitmaps for heart and face emojis
byte heart[8] = {
B00000000,
B01010010,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00000000
};
byte face[8] = {
B00000000,
B01100110,
B10000001,
B10000001,
B10100101,
B10000001,
B01000010,
B00111100
};
void setup() {
// Initialize the MAX7219
for (int device = 0; device < NUM_DEVICES; device++) {
lc.shutdown(device, false); // Wake up the MAX7219 from power-saving mode
lc.setIntensity(device, 8); // Set brightness level (0 is min, 15 is max)
lc.clearDisplay(device); // Clear the display
}
}
void loop() {
// Display heart emoji
displayEmoji(heart);
delay(2000); // Display for 2 seconds
// Clear the display
clearAllDisplays();
delay(500); // Short pause before next emoji
// Display face emoji
displayEmoji(face);
delay(2000); // Display for 2 seconds
// Clear the display
clearAllDisplays();
delay(500); // Short pause before looping again
}
// Function to clear all displays
void clearAllDisplays() {
for (int device = 0; device < NUM_DEVICES; device++) {
lc.clearDisplay(device);
}
}
// Function to display an emoji on all 4 units
void displayEmoji(byte emoji[8]) {
for (int device = 0; device < NUM_DEVICES; device++) {
for (int row = 0; row < 8; row++) {
lc.setRow(device, row, emoji[row]);
}
}
}