반응형
▣ 4개의 방향으로 화살표 표시하기
#include "LedControl.h"
// LedControl 객체 생성: (DIN 핀, CLK 핀, CS 핀, 디바이스 수)
LedControl lc = LedControl(12, 11, 10, 1);
// 위로 향하는 화살표 (0도)
byte arrowUp[8] = {
B00011000, // Row0: 화살표 머리
B00111100, // Row1: 화살표 머리
B01111110, // Row2: 화살표 머리
B00011000, // Row3: 화살표 몸통
B00011000, // Row4: 화살표 몸통
B00011000, // Row5: 화살표 몸통
B00011000, // Row6: 화살표 몸통
B00011000 // Row7: 화살표 몸통
};
// 오른쪽으로 향하는 화살표 (90도)
byte arrowRight[8] = {
B00000000, // Row0
B00000100, // Row1
B00000110, // Row2
B11111111, // Row3
B11111111, // Row4
B00000110, // Row5
B00000100, // Row6
B00000000 // Row7
};
// 아래로 향하는 화살표 (180도)
byte arrowDown[8] = {
B00011000, // Row0: 화살표 몸통
B00011000, // Row1: 화살표 몸통
B00011000, // Row2: 화살표 몸통
B00011000, // Row3: 화살표 몸통
B00011000, // Row4: 화살표 몸통
B01111110, // Row5: 화살표 머리
B00111100, // Row6: 화살표 머리
B00011000 // Row7: 화살표 머리
};
// 왼쪽으로 향하는 화살표 (270도)
byte arrowLeft[8] = {
B00000000, // Row0
B00100000, // Row1
B01100000, // Row2
B11111111, // Row3
B11111111, // Row4
B01100000, // Row5
B00100000, // Row6
B00000000 // Row7
};
void setup() {
lc.shutdown(0, false); // 디스플레이 켜기
lc.setIntensity(0, 8); // 밝기 설정 (0~15, 8은 중간 밝기)
lc.clearDisplay(0); // 화면 지우기
}
void displayPattern(byte pattern[8]) {
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, pattern[row]); // 각 행에 패턴 설정
}
}
void loop() {
// 0도 (위로)
displayPattern(arrowUp);
delay(1000); // 1초 대기
// 90도 (오른쪽으로)
displayPattern(arrowRight);
delay(1000); // 1초 대기
// 180도 (아래로)
displayPattern(arrowDown);
delay(1000); // 1초 대기
// 270도 (왼쪽으로)
displayPattern(arrowLeft);
delay(1000); // 1초 대기
}
Dot Matrix Tool - LCD Font Generator
Left mouse button to draw. Right mouse button (or ctrl+left) to erase.
dotmatrixtool.com
▣ 지그재그 패턴
#define MAX7219_CLK (11)
#define MAX7219_CS (10)
#define MAX7219_DIN (12)
#define DECODE_MODE_ADDR (0x09)
#define DECODE_MODE_VAL (0x00)
#define INTENSITY_ADDR (0x0A) //Bright Setting (0x00 ~ 0x0F)
#define INTENSITY_VAL (0x01)
#define SCAN_LIMIT_ADDR (0x0B) //How many use digit led (line count in matrix led device)
#define SCAN_LIMIT_VAL (0x07)
#define POWER_DOWN_MODE_ADDR (0x0C)
#define POWER_DOWN_MODE_VAR (0x01)
#define TEST_DISPLAY_ADDR (0x0F)
#define TEST_DISPLAY_VAL (0x00)
void write_to_max7219(uint8_t addr, uint8_t value)
{
digitalWrite(MAX7219_CS, LOW); //ChipSelect to LOW
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, addr);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, value);
digitalWrite(MAX7219_CS, HIGH); //ChipSelect to HIGH
}
void init_max7219(void)
{
pinMode(MAX7219_CLK, OUTPUT);
pinMode(MAX7219_CS, OUTPUT);
pinMode(MAX7219_DIN, OUTPUT);
//settings
write_to_max7219(DECODE_MODE_ADDR, DECODE_MODE_VAL);
write_to_max7219(INTENSITY_ADDR, INTENSITY_VAL);
write_to_max7219(SCAN_LIMIT_ADDR, SCAN_LIMIT_VAL);
write_to_max7219(POWER_DOWN_MODE_ADDR, POWER_DOWN_MODE_VAR);
write_to_max7219(TEST_DISPLAY_ADDR, TEST_DISPLAY_VAL);
}
void setup()
{
Serial.begin(115200);
init_max7219();
}
void loop()
{
static unsigned int pattern = 0;
unsigned int i;
unsigned char display_data[2][8] = {
{0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55},
{0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa},
};
for (i = 0; i < 8; i++) {
write_to_max7219(i+1, display_data[pattern][i]);
}
pattern = !pattern;
delay(500);
}
▣ 첫번째 행 LED 순착적으로 깜빡이기
8x8 도트 매트릭스 LED 디스플레이의 특정 행(여기서는 첫 번째 행, selected_row = 0)에서 LED를 한 열씩 순차적으로 켜고 끄며 순환 점등 효과를 만듭니다. 즉, 한 행에서 LED가 왼쪽에서 오른쪽으로 이동하는 애니메이션을 구현합니다.
#include "LedControl.h"
// LedControl 객체 생성: (DIN 핀, CLK 핀, CS 핀, 디바이스 수)
LedControl lc = LedControl(12, 11, 10, 1);
// 선택할 행 번호 (0~7, 여기서는 첫 번째 행)
const int selected_row = 0;
void setup() {
lc.shutdown(0, false); // 디스플레이 켜기
lc.setIntensity(0, 8); // 밝기 설정 (0~15, 8은 중간 밝기)
lc.clearDisplay(0); // 화면 지우기
}
int prev_col = 0;
int current_col = 0;
void loop() {
// 이전 LED 끄기
lc.setLed(0, selected_row, prev_col, false);
// 현재 LED 켜기
lc.setLed(0, selected_row, current_col, true);
// 상태 업데이트
prev_col = current_col;
current_col = (current_col + 1) % 8; // 8열을 순환
delay(200); // 200ms 대기
}
핀 설정: LedControl lc = LedControl(12, 11, 10, 1);
- DIN (데이터 입력): Arduino의 12번 핀
- CLK (클럭 신호): 11번 핀
- CS (칩 선택): 10번 핀
- 1: 연결된 디바이스 수 (여기서는 하나의 MAX7219 칩 사용)
전역 변수: int prev_col = 0; int current_col = 0;
- prev_col: 이전에 켜졌던 열 번호를 저장합니다.
- current_col: 현재 켜질 열 번호를 저장합니다.
동작:
lc.setLed(0, selected_row, prev_col, false);
이전에 켜져 있던 LED (행: selected_row, 열: prev_col)를 끕니다.
lc.setLed(0, selected_row, current_col, true);
현재 열(current_col)의 LED를 켭니다.
prev_col = current_col;
다음 루프에서 현재 LED를 끄기 위해 prev_col을 현재 열로 업데이트합니다.
current_col = (current_col + 1) % 8;
다음 열로 이동합니다. % 8은 열 번호가 0~7 범위를 벗어나지 않도록 순환시킵니다(0 → 1 → ... → 7 → 0).
delay(200);
200ms 동안 대기하여 LED 전환 속도를 조절합니다. 즉, 0.2초마다 LED가 이동합니다.
▣ 첫번째 부터 8번때 행 LED 순착적으로 깜빡이기
#include "LedControl.h"
// LedControl 객체 생성: (DIN 핀, CLK 핀, CS 핀, 디바이스 수)
LedControl lc = LedControl(12, 11, 10, 1);
// 현재 행 번호 (0: 첫 번째 행, 1: 두 번째 행)
int current_row = 0;
// 열 상태 변수
int prev_col = 0;
int current_col = 0;
// 행 순환 카운터 (두 행이 모두 완료되었는지 확인)
int row_cycle_count = 0;
void setup() {
lc.shutdown(0, false); // 디스플레이 켜기
lc.setIntensity(0, 8); // 밝기 설정 (0~15, 8은 중간 밝기)
lc.clearDisplay(0); // 화면 지우기
}
void loop() {
// 이전 LED 끄기
lc.setLed(0, current_row, prev_col, false);
// 현재 LED 켜기
lc.setLed(0, current_row, current_col, true);
// 상태 업데이트
prev_col = current_col;
current_col = (current_col + 1) % 8; // 8열을 순환
// 열이 한 바퀴 돌면 다음 행으로 이동
if (current_col == 0) {
current_row = (current_row + 1) % 2; // 0번 행과 1번 행만 사용
row_cycle_count++; // 행 순환 카운터 증가
}
// 두 행이 모두 완료되면 화면 지우고 초기화
if (row_cycle_count >= 2) {
lc.clearDisplay(0); // 화면 지우기
current_row = 0; // 첫 번째 행으로 리셋
prev_col = 0; // 열 상태 리셋
current_col = 0; // 열 상태 리셋
row_cycle_count = 0; // 카운터 리셋
}
delay(200); // 200ms 대기
}

반응형
'★ 아두이노' 카테고리의 다른 글
| 아두이노 호환 보드 & MAX7219CNG #4 (0) | 2025.09.28 |
|---|---|
| 아두이노 호환 보드 & MAX7219CNG #3 (0) | 2025.09.22 |
| 아두이노 호환 보드 & MAX7219CNG #1 (0) | 2025.09.20 |
| ESP32-WROOM-32] Wifi 설정 (0) | 2025.09.17 |
| ESP32-WROOM-32] 보드 설정 (0) | 2025.09.17 |