#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 three different emojis
byte emoji1[8] = {
0b00111100,
0b01000010,
0b10100101,
0b10000001,
0b10100101,
0b10011001,
0b01000010,
0b00111100
};
byte emoji2[8] = {
0b00111100,
0b01000010,
0b10000001,
0b10100101,
0b10000001,
0b10011001,
0b01000010,
0b00111100
};
byte emoji3[8] = {
0b00111100,
0b01000010,
0b10011001,
0b10100101,
0b10011001,
0b10000001,
0b01000010,
0b00111100
};
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 the first emoji
displayEmoji(emoji1);
delay(2000); // Display for 2 seconds
// Clear the display
clearAllDisplays();
delay(500); // Short pause before next emoji
// Display the second emoji
displayEmoji(emoji2);
delay(2000); // Display for 2 seconds
// Clear the display
clearAllDisplays();
delay(500); // Short pause before next emoji
// Display the third emoji
displayEmoji(emoji3);
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]);
}
}
}