Hardware Setup:
- LED Matrix: 8x8 LED matrix with MAX7219 controller (the common 16-pin module)
- Connections:
- VCC → 5V
- GND → GND
- DIN → Pin 11
- CS → Pin 10
- CLK → Pin 13
- Potentiometers: Connect middle pins to A0 and A1, outer pins to GND and 5V
Features:
- Multiple Display Modes: Potentiometer 1 switches between 5 different patterns
- Brightness Control: Potentiometer 2 controls the LED brightness
- Interactive Patterns:
- Moving dot controlled by both potentiometers
- Smiley face pattern
- Heart pattern
- Arrow pattern
- Spinning line animation
Required Library:
You'll need to install the LedControl library:
- Go to Arduino IDE → Tools → Manage Libraries
- Search for "LedControl" by Eberhard Fahle
- Install it
How It Works:
- Turn potentiometer 1 to cycle through different display patterns
- Turn potentiometer 2 to adjust brightness or control the Y-position (depending on mode)
- The serial monitor shows real-time values for debugging
The code is well-commented and includes additional functions you can explore, like a test mode for all LEDs and a foundation for scrolling text. You can easily modify the patterns or add your own custom designs by creating new byte arrays!
/*
LED Matrix Display with Arduino Uno and 2 Potentiometers
Hardware Required:
- Arduino Uno
- 8x8 LED Matrix with MAX7219 controller (16-pin)
- 2 Potentiometers (10kΩ recommended)
- Jumper wires
- Breadboard
Connections:
LED Matrix (MAX7219):
- VCC -> 5V
- GND -> GND
- DIN -> Pin 11 (MOSI)
- CS -> Pin 10
- CLK -> Pin 13 (SCK)
Potentiometers:
- Pot 1: Left pin to GND, Middle pin to A0, Right pin to 5V
- Pot 2: Left pin to GND, Middle pin to A1, Right pin to 5V
*/
#include <LedControl.h>
// Initialize the LED matrix
// Pin 11 is connected to the DataIn (DIN)
// Pin 13 is connected to the CLK (Clock)
// Pin 10 is connected to CS (Chip Select)
// We have only 1 MAX7219
LedControl lc = LedControl(11, 13, 10, 1);
// Potentiometer pins
const int pot1Pin = A0; // Controls X position or pattern
const int pot2Pin = A1; // Controls Y position or brightness
// Variables
int pot1Value = 0;
int pot2Value = 0;
int ledX = 0;
int ledY = 0;
int brightness = 8;
// Pattern arrays for different displays
byte smiley[8] = {
B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100
};
byte heart[8] = {
B00000000,
B01100110,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00000000
};
byte arrow[8] = {
B00001000,
B00001100,
B00001110,
B11111111,
B11111111,
B00001110,
B00001100,
B00001000
};
void setup() {
Serial.begin(9600);
// Initialize the MAX7219 device
lc.shutdown(0, false); // Wake up displays
lc.setIntensity(0, 8); // Set brightness level (0 is min, 15 is max)
lc.clearDisplay(0); // Clear display register
Serial.println("LED Matrix with Potentiometers Ready!");
Serial.println("Pot 1 (A0): Controls pattern/X position");
Serial.println("Pot 2 (A1): Controls brightness/Y position");
}
void loop() {
// Read potentiometer values
pot1Value = analogRead(pot1Pin);
pot2Value = analogRead(pot2Pin);
// Map potentiometer values to useful ranges
int pattern = map(pot1Value, 0, 1023, 0, 4); // 5 different patterns/modes
brightness = map(pot2Value, 0, 1023, 0, 15); // Brightness from 0 to 15
// Set brightness based on pot2
lc.setIntensity(0, brightness);
// Clear the display
lc.clearDisplay(0);
// Display different patterns based on pot1 value
switch(pattern) {
case 0:
// Single moving dot
ledX = map(pot1Value, 0, 1023, 0, 7);
ledY = map(pot2Value, 0, 1023, 0, 7);
lc.setLed(0, ledY, ledX, true);
break;
case 1:
// Display smiley face
displayPattern(smiley);
break;
case 2:
// Display heart
displayPattern(heart);
break;
case 3:
// Display arrow
displayPattern(arrow);
break;
case 4:
// Custom animation - spinning line
displaySpinningLine();
break;
}
// Print values to serial monitor for debugging
Serial.print("Pot1: ");
Serial.print(pot1Value);
Serial.print(" | Pot2: ");
Serial.print(pot2Value);
Serial.print(" | Pattern: ");
Serial.print(pattern);
Serial.print(" | Brightness: ");
Serial.println(brightness);
delay(100); // Small delay for stability
}
// Function to display a pattern from an array
void displayPattern(byte pattern[8]) {
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, pattern[i]);
}
}
// Function to display a spinning line animation
void displaySpinningLine() {
static int linePosition = 0;
static unsigned long lastUpdate = 0;
// Update animation every 200ms
if (millis() - lastUpdate > 200) {
lc.clearDisplay(0);
// Draw line based on position
switch(linePosition) {
case 0: // Horizontal line
for (int i = 0; i < 8; i++) {
lc.setLed(0, 3, i, true);
}
break;
case 1: // Diagonal line /
for (int i = 0; i < 8; i++) {
lc.setLed(0, 7-i, i, true);
}
break;
case 2: // Vertical line
for (int i = 0; i < 8; i++) {
lc.setLed(0, i, 3, true);
}
break;
case 3: // Diagonal line \
for (int i = 0; i < 8; i++) {
lc.setLed(0, i, i, true);
}
break;
}
linePosition = (linePosition + 1) % 4;
lastUpdate = millis();
}
}
// Additional function: Test all LEDs
void testAllLEDs() {
// Turn on all LEDs
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
lc.setLed(0, row, col, true);
delay(50);
}
}
delay(1000);
// Turn off all LEDs
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
lc.setLed(0, row, col, false);
delay(50);
}
}
}
// Function to create scrolling text effect (bonus feature)
void scrollText(String text) {
// This is a simplified version - you can expand it
// to create actual scrolling text patterns
for (int i = 0; i < text.length(); i++) {
lc.clearDisplay(0);
// You would need to define character patterns here
delay(500);
}
}