#define CLK 13
#define DIN 11
#define CS 10
#define X_SEGMENTS 4
#define Y_SEGMENTS 4
#define NUM_SEGMENTS (X_SEGMENTS * Y_SEGMENTS)
// Framebuffer for the LED matrix
byte fb[8 * NUM_SEGMENTS];
// Pixel data for a 32x32 Rizz Face
const uint8_t rizzFace[32][4] = {
{0b00000000, 0b00000000, 0b00000000, 0b00000000}, // Row 1
{0b00000000, 0b00011110, 0b01111000, 0b00000000}, // Row 2
{0b00000000, 0b00111111, 0b11111100, 0b00000000}, // Row 3
{0b00000000, 0b01111111, 0b11111110, 0b00000000}, // Row 4
{0b00000000, 0b01111100, 0b00111110, 0b00000000}, // Row 5
{0b00000000, 0b01111100, 0b00111110, 0b00000000}, // Row 6
{0b00000000, 0b01111000, 0b00011110, 0b00000000}, // Row 7
{0b00000000, 0b01110000, 0b00001110, 0b00000000}, // Row 8
{0b00000000, 0b01110000, 0b00001110, 0b00000000}, // Row 9
{0b00000000, 0b01111000, 0b00011110, 0b00000000}, // Row 10
{0b00000000, 0b00111100, 0b00111100, 0b00000000}, // Row 11
{0b00000000, 0b00111110, 0b01111100, 0b00000000}, // Row 12
{0b00000000, 0b00011111, 0b11111100, 0b00000000}, // Row 13
{0b00000000, 0b00001111, 0b11111000, 0b00000000}, // Row 14
{0b00000000, 0b00000111, 0b11110000, 0b00000000}, // Row 15
{0b00000000, 0b00000011, 0b11100000, 0b00000000}, // Row 16
{0b00000000, 0b00000001, 0b11000000, 0b00000000}, // Row 17
{0b00000000, 0b00000001, 0b11000000, 0b00000000}, // Row 18
{0b00000000, 0b00000011, 0b11100000, 0b00000000}, // Row 19
{0b00000000, 0b00000111, 0b11110000, 0b00000000}, // Row 20
{0b00000000, 0b00001111, 0b11111000, 0b00000000}, // Row 21
{0b00000000, 0b00011111, 0b11111100, 0b00000000}, // Row 22
{0b00000000, 0b00111110, 0b01111110, 0b00000000}, // Row 23
{0b00000000, 0b01111100, 0b00111110, 0b00000000}, // Row 24
{0b00000000, 0b01111000, 0b00011110, 0b00000000}, // Row 25
{0b00000000, 0b01110000, 0b00001110, 0b00000000}, // Row 26
{0b00000000, 0b01110000, 0b00001110, 0b00000000}, // Row 27
{0b00000000, 0b01111000, 0b00011110, 0b00000000}, // Row 28
{0b00000000, 0b00111100, 0b00111100, 0b00000000}, // Row 29
{0b00000000, 0b00011110, 0b01111000, 0b00000000}, // Row 30
{0b00000000, 0b00001111, 0b11110000, 0b00000000}, // Row 31
{0b00000000, 0b00000000, 0b00000000, 0b00000000} // Row 32
};
void shiftAll(byte send_to_address, byte send_this_data) {
digitalWrite(CS, LOW);
for (int i = 0; i < NUM_SEGMENTS; i++) {
shiftOut(DIN, CLK, MSBFIRST, send_to_address);
shiftOut(DIN, CLK, MSBFIRST, send_this_data);
}
digitalWrite(CS, HIGH);
}
void setup() {
pinMode(CLK, OUTPUT);
pinMode(DIN, OUTPUT);
pinMode(CS, OUTPUT);
shiftAll(0x0f, 0x00); // Display test register - test mode off
shiftAll(0x0b, 0x07); // Scan limit register - display digits 0 to 7
shiftAll(0x0c, 0x01); // Shutdown register - normal operation
shiftAll(0x0a, 0x08); // Intensity register - medium brightness
shiftAll(0x09, 0x00); // Decode mode register - no decode
}
void loop() {
displayRizzFace();
delay(500);
}
void displayRizzFace() {
for (int row = 0; row < 32; row++) {
for (int segment = 0; segment < X_SEGMENTS; segment++) {
byte data = rizzFace[row][segment];
digitalWrite(CS, LOW);
for (int i = 0; i < NUM_SEGMENTS; i++) {
if (i / X_SEGMENTS == row / 8 && i % X_SEGMENTS == segment) {
shiftOut(DIN, CLK, MSBFIRST, row % 8 + 1);
shiftOut(DIN, CLK, MSBFIRST, data);
} else {
shiftOut(DIN, CLK, MSBFIRST, 0);
shiftOut(DIN, CLK, MSBFIRST, 0);
}
}
digitalWrite(CS, HIGH);
}
}
}