#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 = 1;
// Create a LedControl instance
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, NUM_DEVICES);
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() {
// Move a column from left to right across all devices
moveColumnLeftToRight();
delay(1); // Pause before moving to row display
// Clear the display
clearAllDisplays();
delay(1); // Short pause
// Move a row from top to bottom across all devices
moveRowLeftToRight();
delay(1); // Pause before looping again
// Clear the display
clearAllDisplays();
delay(1); // Short pause
}
// Function to move a column from left to right across all devices
void moveColumnLeftToRight() {
for (int col = 0; col < 8; col++) {
for (int device = 0; device < NUM_DEVICES; device++) {
lc.setColumn(device, col, B11111111); // Set the entire column on
delay(200); // Delay between movements
lc.setColumn(device, col, B00000000); // Clear the column
}
}
}
// Function to move a row from top to bottom across all devices
void moveRowLeftToRight() {
for (int row = 0; row < 8; row++) {
for (int device = 0; device < NUM_DEVICES; device++) {
lc.setRow(device, row, B11111111); // Set the entire row on
delay(200); // Delay between movements
lc.setRow(device, row, B00000000); // Clear the row
}
}
}
// Function to clear all displays
void clearAllDisplays() {
for (int device = 0; device < NUM_DEVICES; device++) {
lc.clearDisplay(device);
}
}