





| Controlling a Led matrix or 7-segment displays with the MAX7219 or the MAX7221 |
| 站長Blog文章單元 - Arduino擴充IO (PWM IC, LED Driver IC, Digital/Analo) | |||||||||||||||||||||||||||||||||||||||
| 作者是 Administrator | |||||||||||||||||||||||||||||||||||||||
| 週五, 28 五月 2010 17:25 | |||||||||||||||||||||||||||||||||||||||
|
光使用單晶片的IO沒有辦法驅動需要大量IO環境的LED顯示,解決的方式是利用掃描的方式來達成,所謂的掃描指利用快速的ON/OFF方式來驅動LED。例如: 共陰極七段顯示器,一顆七段顯示器有八組。利用一顆MAX7219 MAX7221可以以三條線來控制8科七段顯示器,即64個IO。首先,你需要先下載晶片的使用手冊你可以從google搜尋打maxim 7219 datasheet或是點選下方連結下載。Reference: Controlling a Led matrix with the
電路圖
基本線路與Arduino搭配
電路中需要兩個電容10uF和100nF(104),電阻的部分是控制MAXIM晶片輸出的電流和電壓,所以你必須參考所要驅動的LED來更改電阻的大小。下方列出電阻對應的表格:
挑選電容 挑選RSet電阻(依據MAX7219 SPEC中的表格)
舉例來說,我有一顆8x8矩陣LED(共64顆),每一顆額定電流是40mA,電壓是3.1V,那麼選10.6K的電阻。但是手邊的電阻沒有相對的話,你可以使用歐姆定律,利用幾顆電阻來組合出你所需要的電阻總值。 R = r1*r2 / r1+r2 ; 10.6K ~= 10K + 0.6K = 10K 串聯 (1K並聯2K) =10.666666....KΩ
其他狀況,就只要使用 軟體 [下載] 測試電路:(七段顯示器依不同廠牌腳位有所差異) 測試程式碼:
#include "LedControl.h"
/*
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
*/
LedControl lc=LedControl(12,11,10,1);
//LedControl lc=LedControl(12,11,10,2); //如果有個位與十位數,兩顆七段顯示
unsigned long delaytime=200;
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
}
void setDisplay(int which7219,int which7segments,char value){
lc.setChar(which7219,which7segments,value,true);
delay(delaytime);
}
void printNumber(int v) {
int ones;
int tens;
int hundreds;
boolean negative;
if(v < -999 || v > 999)
return;
if(v<0) {
negative=true;
v=v*-1;
}
ones=v%10;
v=v/10;
tens=v%10;
v=v/10;
hundreds=v;
if(negative) {
//print character '-' in the leftmost column
lc.setChar(0,3,'-',false);
}
else {
//print a blank in the sign column
lc.setChar(0,3,' ',false);
}
//Now print the number digit by digit
lc.setDigit(0,2,(byte)hundreds,false);
lc.setDigit(0,1,(byte)tens,false);
lc.setDigit(0,0,(byte)ones,false);
}
void loop() {
for(int x=0;x<99;x++){
printNumber(x);
}
}
setDigit 參數說明
/* * Display a (hexadecimal) digit on a 7-Segment Display * Params: * addr address of the display * digit the position of the digit on the display (0..7) * value the value to be displayed. (0x00..0x0F) * dp sets the decimal point. */ void setDigit(int addr, int digit, byte value, boolean dp); 效果: 控制矩陣LED![]() 控制七段顯示器![]() Reference [link][link][example]
============== #include "LedControl.h"
|
|||||||||||||||||||||||||||||||||||||||
| 最近更新在 週日, 04 七月 2010 17:00 | |||||||||||||||||||||||||||||||||||||||