#include <LedControl.h>
// Pin connection
const int DATA_IN = 2;
const int CLK = 4;
const int LOAD = 3;
const int MAX_DEVICES = 4; // 4 modules of 8x8 = 32x8
LedControl lc = LedControl(DATA_IN, CLK, LOAD, MAX_DEVICES);
void setup() {
for (int i = 0; i < MAX_DEVICES; i++) {
lc.shutdown(i, false); // Wake up displays
lc.setIntensity(i, 8); // Set brightness level (0 is min, 15 is max)
lc.clearDisplay(i); // Clear display register
}
}
void loop() {
// Draw eyes in both modules
for (int i = 0; i < 4; i++) {
drawEyes(i);
delay(100); // Wait for 100 milliseconds
}
// Draw eyes in both modules in reverse order
for (int i = 3; i >= 0; i--) {
drawEyes(i);
delay(100); // Wait for 100 milliseconds
}
}
void drawEyes(int stage) {
byte eyeOpen[8] = {
B00111100,
B01000010,
B10011001,
B10111101,
B10111101,
B10011001,
B01000010,
B00111100,
};
byte eyeQuarterClosed[8] = {
B00000000,
B01111110,
B10011001,
B10111101,
B10111101,
B10011001,
B01111110,
B00000000,
};
byte eyeThirdClosed[8] = {
B00000000,
B00000000,
B00111100,
B11111111,
B11111111,
B00111100,
B00000000,
B00000000,
};
byte eyeClosed[8] = {
B00000000,
B00000000,
B00000000,
B11111111,
B11111111,
B00000000,
B00000000,
B00000000
};
byte *eyePattern;
// Select pattern based on stage
switch (stage) {
case 0:
eyePattern = eyeOpen;
break;
case 1:
eyePattern = eyeQuarterClosed;
break;
case 2:
eyePattern = eyeThirdClosed;
break;
case 3:
eyePattern = eyeClosed;
break;
default:
eyePattern = eyeOpen; // Default to open if invalid stage
break;
}
// Display the left half of the eye on modules 3 and 4 (right eye)
for (int row = 0; row < 8; row++) {
lc.setRow(2, row, eyePattern[row] & 0xFF00 >> 8); // Module 3
lc.setRow(3, row, eyePattern[row] & 0x00FF); // Module 4
}
// Display the right half of the eye on modules 1 and 2 (left eye)
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, eyePattern[row] & 0xFF00 >> 8); // Module 1
lc.setRow(1, row, eyePattern[row] & 0x00FF); // Module 2
}
// Clear other modules
for (int device = 4; device < MAX_DEVICES; device++) {
lc.clearDisplay(device);
}
}