A heart on the matrix
Section 10: Sensors and screens in codeLesson 10.3 · ⏱ 8 min
The 8×8 matrix has 64 LEDs. We write each row as a binary number: 1 on and 0 off. setRow draws a row.
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte heart[8] = {B00000000, B01100110, B11111111, B11111111, B11111111, B01111110, B00111100, B00011000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, heart[r]);
}
}

🖥️ What happens on the stage?
We ran this code in Robo Maker and the challenge passed: “Bravo! It works”.
💡 Tip
Draw the heart first on 8×8 squared paper, then turn every row into 0s and 1s.
📌 Another example: a smiley face
Eight rows, each with 8 dots: 1 = on, and 0 = off.
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B00111100, B01000010, B10100101, B10000001, B10100101, B10011001, B01000010, B00111100};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
}

✍️ Practise
Draw a heart, then a smiley face.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
An arrow pointing up.
👀 Show the solution🙈 Hide the solution
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B00011000, B00111100, B01111110, B11011011, B00011000, B00011000, B00011000, B00011000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
}

Result: an arrow ⬆.
Medium
A square (just the frame).
👀 Show the solution🙈 Hide the solution
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B11111111, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B11111111};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
}

Result: a square frame.
Hard
The heart beats: it shows for half a second and disappears for half a second.
👀 Show the solution🙈 Hide the solution
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B00000000, B01100110, B11111111, B11111111, B11111111, B01111110, B00111100, B00011000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
delay(500);
lc.clearDisplay(0);
delay(500);
}

Result: a heart that appears and disappears.

