Create a Smiley Face Using LED Matrix With Arduino Nano

by subairui73 in Circuits > Arduino

59 Views, 0 Favorites, 0 Comments

Create a Smiley Face Using LED Matrix With Arduino Nano

IMG_1026.JPG.png

This instructable will demonstrate the basic steps to display a smiley face using LED Matrix with Arduino Nano. Consider this a simplified version of Intractable: LED Matrix with Arduino, featuring an interesting demo without detailed explanations.

Download Library

iShot_2024-11-09_11.29.32.png

First, download the "LedControl" library by Eberhard Fahle.

Build Circuit

iShot_2024-11-09_11.34.44.png
image 2.png

Then, build the circuit with the connections displayed in the table.

Write Code

Next, include the library:


#include <LedControl.h>


Then, define the pins and initialize a LedControl object named lc with specified pins:


#define DIN_PIN 12
#define CS_PIN 11
#define CLK_PIN 10

// Create a LED control instance.
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 1);

After that setup the lc object in the setup function:


void setup() {
// Setup the LED control instance.
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}


Next, declare a byte array to store the face data, where each digital represents an LED in the LED matrix. Then, traverse the array and display each column by calling lc.setColumn(i, j, data):


byte smileFace[8] = {
B00000000, // binary representation starts with B
B01100110,
B01100110,
B00000000,
B10000001,
B01000010,
B00111100,
B00000000
};

void setup() {
// ...
displayMatrixRow(smileFace);
}

void displayMatrixRow(byte *face) {
lc.clearDisplay(0); // Clear last display
for (int i = 0; i < 8; i++) lc.setColumn(0, 7 - i, face[i]);
}

Adapt to More Situations

IMG_1026.JPG.png

Finally modify your code to adapt to more situations:

  1. Display the LED matrix in the loop for continuous updating
  2. Display the LED matrix in different orientations
  3. Create and display a sad face

Here’ the complete code:

#include <LedControl.h>

#define DIN_PIN 12
#define CS_PIN 11
#define CLK_PIN 10

// Create a LED control instance.
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 1);

byte smileFace[8] = {
B00000000,
B01100110,
B01100110,
B00000000,
B10000001,
B01000010,
B00111100,
B00000000
};

byte sadFace[8] = {
B00000000,
B01100110,
B01100110,
B00000000,
B00111100,
B01000010,
B10000001,
B00000000
};

void setup() {
// Setup the LED control instance.
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
displayMatrixRow(smileFace);
}

void loop() {
// Try this!
// displayMatrixColumn(sadFace);
// delay(1000);
}

void displayMatrixColumn(byte *face) {
lc.clearDisplay(0); // Clear last display
for (int i = 0; i < 8; i++) lc.setColumn(0, 7 - i, face[i]);
}

void displayMatrixRow(byte *face) {
lc.clearDisplay(0); // Clear last display
for (int i = 0; i < 8; i++) lc.setRow(0, i, face[i]);
}