Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
lois li
Published © CERN-OHL2

8x8 LED Matrix

This project showcases a heartbeat flowing light effect on an 8x8 LED matrix using an Arduino UNO development board.

BeginnerProtip2 hours23

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×1
Through Hole Resistor, 10 ohm
Through Hole Resistor, 10 ohm
×1

Software apps and online services

Online Simulation
PCBX Online Simulation

Hand tools and fabrication machines

Materia 101
Arduino Materia 101

Story

Read more

Schematics

8x8 LED Matrix

This project showcases a heartbeat flowing light effect on an 8x8 LED matrix using an Arduino UNO development board.

Code

Untitled file

Arduino
// Define the pins for the 8x8 LED matrix
int led_row[8] = {2, 3, 4, 5, 6, 7, 8, 9};
int led_col[8] = {10, 11, 12, 13, A0, A1, A2, A3};

// Coordinates of the LED that need to be lit
const int coords_1[18] = {
    2, 4,
    1, 2,
    0, 1,
    1, 0,
    2, 0,
    3, 0,
    4, 1,
    5, 2,
    6, 3
};
const int coords_2[21] = {
    0, 1, 1,
    1, 0, 2,
    2, 0, 3,
    3, 0, 3,
    4, 1, 6,
    5, 2, 5,
    6, 3, 4
};

void setup() {
    for (int i = 0; i < 8; i++) {
        pinMode(led_row[i], OUTPUT);
        pinMode(led_col[i], OUTPUT);
    }
}

void loop() {
    for (int i = 0; i < 9; i++) {
        display(coords_1[i*2], coords_1[i*2+1]);     
    }
    for (int i = 9; i > 0; i--) {
        display(coords_1[i*2], coords_1[i*2+1]); 
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 7; j++) {
            display_all(coords_2[j*3], coords_2[j*3+1], coords_2[j*3+2]); 
        }
    }
}

// Turn off the entire LED matrix
void reset_all() {
    for (int row = 0; row < 8; row++) {
        digitalWrite(led_row[row], LOW);
        for (int col = 0; col < 8; col++) {
            digitalWrite(led_col[col], HIGH);
        }
    }
}

// Light up the LED at the corresponding coordinates in the matrix
void display(int y, int x) {
    reset_all();
    for (int row = 0; row < 8; row++) {
        if (row == y) {
            digitalWrite(led_row[row], HIGH);
            for (int col = 0; col < 8; col++) {
                if (col == x) {
                    digitalWrite(led_col[col], LOW);
                    digitalWrite(led_col[7-col], LOW);
                }
            }
        }
    }
    delay(80); // Adjust the speed
}

// Light up all the LEDs within the area enclosed by the aforementioned coordinates
void display_all(int y, int x1, int x2) {
    reset_all();
    for (int row = 0; row < 8; row++) {
        if (row == y) {
            digitalWrite(led_row[row], HIGH);
            for (int col = 0; col < 8; col++) {
                if (col >= x1 && col <= x2) {
                    digitalWrite(led_col[col], LOW);
                    digitalWrite(led_col[7-col], LOW);
                }
            }
            delay(50); // Adjust the speed
        }
    }
}

Credits

lois li
5 projects • 0 followers

Comments