You are on page 1of 7

8/12/2019 23-max7219-ledcontroller - ePlearn

ePlearn Search this site

Arduino Project >


23-max7219-ledcontroller

Max 7219 LED Driver

ลักษณของ 8x8 led matrix

Datsheet Max7219

การต่อ LED Matrix 1 ชุด

การทดลอง ควบคุม 8x8 led matrix 1 ชุด

1. ต่อวงจรตามรูป

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 1/7
8/12/2019 23-max7219-ledcontroller - ePlearn

2.ติดตัง library max7219 ลงใน libraries floder ของ sketch โดยดาวน์โหลด LedControlMS.rar จาก อินเตอร์เนทหรือจากไฟล์ด ้านล่าง
สําหรับผู ้ทียังติดตังไม่เป็ นให ้ทําตามขันตอน 2.1-2.4
การติดตัง library max7219 ให ้ Arduino มองเห็น
2.1 ดาวน์โหลด LedControlMS.rar จาก ทีนี
2.2 ขยายไฟล์ แล ้วนํ าไปวางที โฟล์เดอร์ libraries ใน sketch
2.3 ปิ ดโปรแกรม Arduino แล ้วเปิ ดใหม่
2.4 ตรวจว่าเห็น library โดยใช ้เมนูไฟล์ แล ้วเลือก example จะต ้องพบกลุม
่ ตัวอย่าง LedControlMS ตามรูป

3. เขียนโปรแกรม

โปรแกรมที 1
-----------------------------------------------------------------------------------------------------------
#include "LedControlMS.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD (CS)
We have only a single MAX72XX.
*/

#define NBR_MTX 1 //จํานวน LED Module

LedControl lc=LedControl(12,11,10, NBR_MTX);

void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a low value */
lc.setIntensity(0,0);
/* and clear the display */
lc.clearDisplay(0);

delay(100);
lc.clearAll();
lc.setRow(0, 0, 0xff);
lc.setRow(0, 1, 0xfe);
lc.setRow(0, 2, 0xfc);
lc.setRow(0, 3, 0xf8);
lc.setRow(0, 4, 0xf0);
lc.setRow(0, 5, 0xe0);

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 2/7
8/12/2019 23-max7219-ledcontroller - ePlearn
lc.setRow(0, 6, 0xc0);
lc.setRow(0, 7, 0x80);
}

void loop(){
}
-----------------------------------------------------------------------------------------------------------

อธิบายความหมาย

ั void setRow(int addr, int row, byte value);


ฟั งก์ชน
addr เป็ นตําแหน่งของโมดูล LED เริมจาก 0 กรณีทมี ี ตวั เดียวให ้เป็ น 0
row แถวทีของ LED เริมจากซ ้ายมือแถวที 0 ไปทางขวามือ

value ค่าทีใช ้กําหนดการติดดับของ LED แต่ละดวงในแถวนัน ถ ้าให ้ เป็ น 1 จะทําให ้ LED ติด ถ ้าให ้เป็ น 0 จะทําให ้ LED ดับ
โดยนับบิต ที 0 ถึง 7 จากบนลงล่าง

ดังนันค่าตามโปรแกรมจะได ้ รูปเป็ น

นอกจากนีในไลบรารียงั ได ้กําหนด font ใว ้บ ้างแล ้ว สามารถดูได ้จากตัวอย่างในไลบรารี

การต่อ LED หลายๆโมดูลเรียงกันสามารถต่อได ้ดังนี


ปรับปรุงโปรแกรม ทําเป็ นฟั งก์ชน

โปรแกรมที 2
-----------------------------------------------------------------------------------------------------------

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 3/7
8/12/2019 23-max7219-ledcontroller - ePlearn
#include "LedControlMS.h"
#define NBR_MTX 1

// LedControl(DIN,CLK,CS number);
LedControl lc=LedControl(12,11,10, NBR_MTX);

const unsigned char pat1[8] ={0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80};

void display(unsigned char *addr){


unsigned char data;
for (int i=0; i < 8; i++){
data = addr[i];
lc.setRow(0, i, data);
}
}

void setup() {
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup,we have to do a wakeup call
lc.setIntensity(0,0); //Set the brightness to a low value
lc.clearDisplay(0); // and clear the display

delay(100);
lc.clearAll();
display(pat1);
}

void loop(){
}
-----------------------------------------------------------------------------------------------------------

ใช ้ฟั งก์ชน
ั Display แสดงภาพเคลือนไหว โดยใช ้ภาพหลายภาพ

ไฟล์_000.mp4

โปรแกรมที 3
-----------------------------------------------------------------------------------------------------------
#include "LedControlMS.h"
#define NBR_MTX 1

// LedControl(DIN,CLK,CS number);
LedControl lc=LedControl(12,11,10, NBR_MTX);

const char cir1[]={0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00};


const char cir2[]={0x00,0x00,0x00,0x08,0x04,0x02,0x01,0x00};
const char cir3[]={0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00};
const char cir4[]={0x00,0x00,0x00,0x08,0x10,0x20,0x40,0x00};
const char cir5[]={0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00};
const char cir6[]={0x40,0x20,0x10,0x08,0x00,0x00,0x00,0x00};
const char cir7[]={0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00};
const char cir8[]={0x01,0x02,0x04,0x08,0x00,0x00,0x00,0x00};

void display(unsigned char *addr){


unsigned char data;
for (int i=0; i < 8; i++){
data = addr[i];
lc.setRow(0, i, data);
}
}

void setup() {
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup,we have to do a wakeup call
lc.setIntensity(0,0); //Set the brightness to a low value
lc.clearDisplay(0); // and clear the display

delay(100);
lc.clearAll();
}

void loop(){
for (int j=0; j < 8; j++){
display(cir1);
delay(200);
display(cir2);
delay(200);
display(cir3);
delay(200);
display(cir4);
delay(200);
display(cir5);
delay(200);
display(cir6);
delay(200);
display(cir7);
delay(200);

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 4/7
8/12/2019 23-max7219-ledcontroller - ePlearn
display(cir8);
delay(200);
}
}
---------------------------------------------------------------------------
เขียนอีกแบบให ้สันและกระชับขึน max7219-fn-test-5-2.ino

#include "LedControlMS.h"
#define NBR_MTX 1

// LedControl(DIN,CLK,CS number);
LedControl lc=LedControl(12,11,10, NBR_MTX);

const char cir[64]={


0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00, //picture 1
0x00,0x00,0x00,0x08,0x04,0x02,0x01,0x00, //picture 2
0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00, //picture 3
0x00,0x00,0x00,0x08,0x10,0x20,0x40,0x00, //picture 4
0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00, //picture 5
0x40,0x20,0x10,0x08,0x00,0x00,0x00,0x00, //picture 6
0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00, //picture 7
0x01,0x02,0x04,0x08,0x00,0x00,0x00,0x00, //picture 8
};

void display(unsigned char *addr){


unsigned char data;
for (int i=0; i < 8; i++){
data = addr[i];
lc.setRow(0, i, data);
}
}

void setup() {
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup,we have to do a wakeup call
lc.setIntensity(0,0); //Set the brightness to a low value
lc.clearDisplay(0); // and clear the display

delay(100);
lc.clearAll();
}

void loop(){
for (int j=0; j < 8; j++){
display(cir+8*j);
delay(200);
}
}
-----------------------------------------------------------------------------------------------------------

ใช ้ฟั งก์ชน
ั Display แสดงภาพเคลือนไหว แบบใช ้ภาพเดียว ใช ้วิธเี ลือนภาพ

ไฟล์_001.mp4

โปรแกรมที 4
-----------------------------------------------------------------------------------------------------------
#include "LedControlMS.h"
#define NBR_MTX 1

// LedControl(DIN,CLK,CS number);
LedControl lc=LedControl(12,11,10, NBR_MTX);

const unsigned char arrow[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,


0x10,0x38,0x7c,0xfe,0x38,0x38,0x38,0x38,
0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00};
void display(unsigned char *addr){
unsigned char data;
for (int i=0; i < 8; i++){
data = addr[i];
lc.setRow(0, i, data);
}
}

void setup() {
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup,we have to do a wakeup call
lc.setIntensity(0,0); //Set the brightness to a low value
lc.clearDisplay(0); // and clear the display

delay(100);
lc.clearAll();
}

void loop(){
for (int j=0; j < 18; j++){
display(arrow+j);

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 5/7
8/12/2019 23-max7219-ledcontroller - ePlearn
delay(200);
}
}
-----------------------------------------------------------------------------------------------------------

สําหร ับผูท
้ แปลแล้
ี ว Error ให้ทดลองแปล ไฟล์ ในโปรแกรมที 4 max7219-fn-test-4.ino ด้านล่างนี

-----------------------------------------------------------------------------------------------------------

โปรแกรมที 4
ใช ้ฟั งก์ชน
ั displayChar ของ ไลบรารี แสดงเลข 0 ถึง 9
ั จะแสดงตัวอักษรอะไรได ้บ ้าง ดูได ้จากตัวแปร const static byte alphabetBitmap[41][6] ในไฟล์ LedControlMS.h ทีอยูใ่ นโฟล์เดอร์
สําหรับฟั งก์ชนนี
\Arduino\libraries\LedControlMS
-----------------------------------------------------------------------------------------------------------
#include "LedControlMS.h"

#define NBR_MTX 1 //จํานวน LED Module


//LedControl lc=LedControl(Datain,CLK,CS, NBR_MTX);
LedControl lc=LedControl(12,11,10, NBR_MTX);

void setup() {
lc.shutdown(0,false); // do a wakeup call
lc.setIntensity(0,1); // Set the brightness to a low value
lc.clearDisplay(0); // clear the display
delay(100);
}

void loop(){
for (int j=0; j <= 9; j++){
lc.displayChar(0, j);
delay(400);
}
}
-----------------------------------------------------------------------------------------------------------
โปรแกรมที 5
ใช ้ฟั งก์ชน
ั displayChar ของ ไลบรารี แสดงตัวอักษร A ถึง Z
ควรศึกษาวิธก ี ารอ ้างอิง Address .ในตัวแปร Array alphabetBitmap[41][6]
ความหมายของ ('A'-0x41)+(15+j)
เนืองจาก

รหัส ASCII ของตัวอักษร 'A' คือ 0x41


index ของตัวอักษร 'A' ใน ในตัวแปร Array alphabetBitmap[41][6] อยูท
่ ตํ
ี าแหน่ง 15

ดังนันเพือต ้องการให ้การสังพิมพ์ด ้วยการใช ้รหัส ASCII จึงปรับให ้ค่า เช่นถ ้าต ้องการแสดงตัว 'T' ก็ใช ้คําสัง
lc.displayChar(0, ('T'-0x41+15));
หรือบวกลบกันก่อน
-0x41+ 15 = -65+15 = -50
lc.displayChar(0, ('T'-50))

ถ ้าต ้องการแสดงตัวอักษร 'R' ก็ใช ้เป็ น lc.displayChar(0, ('R'-50))

-----------------------------------------------------------------------------------------------------------
#include "LedControlMS.h"

#define NBR_MTX 1 //จํานวน LED Module


//LedControl lc=LedControl(Datain,CLK,CS, NBR_MTX);
LedControl lc=LedControl(12,11,10, NBR_MTX);

void setup() {
lc.shutdown(0,false); // do a wakeup call
lc.setIntensity(0,1); // Set the brightness to a low value
lc.clearDisplay(0); // clear the display
delay(100);
}

void loop(){
for (int j=0; j < 26; j++){
lc.displayChar(0, ('A'-0x41)+(15+j));
delay(400);
}
}
-----------------------------------------------------------------------------------------------------------

Č
ċ LedControlMS.rar (9k) Daddy Moon, Feb 7, 2017, 11:25 AM v.1 ď
Ċ MAX7219-MAX7221.pdf (491k) Narong Buabthong, Jan 16, 2018, 10:49 AM v.1 ď
ċ max7219-fn-test-4.ino (1k) Daddy Moon, Feb 9, 2017, 10:49 PM v.1 ď
ċ max7219-fn-test-5-2.ino (1k) Daddy Moon, Feb 10, 2017, 9:00 AM v.1 ď

Comments

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 6/7
8/12/2019 23-max7219-ledcontroller - ePlearn

Sign in | Recent Site Activity | Report Abuse | Print Page | Powered By Google Sites

https://sites.google.com/site/eplearn/arduino-project/23-max7219-ledcontroller 7/7

You might also like