8*8点阵模块:修訂版本之間的差異
出自YFRobotwiki
第 65 行: | 第 65 行: | ||
<pre > | <pre > | ||
/************************************************** | /************************************************** | ||
− | * Face | + | * Face |
* ( 8x8 Led Dot Matrix with two 74HC595 on Arduino) | * ( 8x8 Led Dot Matrix with two 74HC595 on Arduino) | ||
− | * | + | * |
− | * by YFROBOT | + | * by YFROBOT |
***************************************************/ | ***************************************************/ | ||
#include "TimerOne.h" | #include "TimerOne.h" | ||
+ | #include "face.h" | ||
#define ROW_DATA ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4)|(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0)) | #define ROW_DATA ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4)|(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0)) | ||
第 82 行: | 第 83 行: | ||
//Pin connected to SH_CP of 74HC595 | //Pin connected to SH_CP of 74HC595 | ||
int SRCK = 12; | int SRCK = 12; | ||
− | int row[8]={ | + | int row[8] = { |
− | 0, 0, 0, 0, 0, 0, 0, 0}; | + | 0, 0, 0, 0, 0, 0, 0, 0 |
− | int col[8]={ | + | }; |
− | 0, 0, 0, 0, 0, 0, 0, 0}; | + | int col[8] = { |
+ | 0, 0, 0, 0, 0, 0, 0, 0 | ||
+ | }; | ||
byte screen[8] = { | byte screen[8] = { | ||
− | 0, 0, 0, 0, 0, 0, 0, 0}; | + | 0, 0, 0, 0, 0, 0, 0, 0 |
+ | }; | ||
volatile byte screenRow = 0; | volatile byte screenRow = 0; | ||
volatile byte screenCol = 0; | volatile byte screenCol = 0; | ||
+ | |||
+ | // A counter to know what frame we're showing | ||
+ | int animationIndex = 0; | ||
+ | // 8x8 Point temporary array | ||
+ | byte brightnesses[64]; | ||
void setup() { | void setup() { | ||
第 102 行: | 第 111 行: | ||
void doubleBuffer() { | void doubleBuffer() { | ||
− | row[screenRow]=0; | + | row[screenRow] = 0; |
− | col[screenCol]=1; | + | col[screenCol] = 1; |
screenCol++; | screenCol++; | ||
第 113 行: | 第 122 行: | ||
} | } | ||
} | } | ||
− | if((screen[screenRow] >> screenCol) & B1 == B1) { | + | if ((screen[screenRow] >> screenCol) & B1 == B1) { |
− | row[screenRow]=1; | + | row[screenRow] = 1; |
− | col[screenCol]=0; | + | col[screenCol] = 0; |
− | digitalWrite(RCK,LOW); | + | digitalWrite(RCK, LOW); |
− | shiftOut(COL_DATA); | + | shiftOut(SER, SRCK, MSBFIRST, COL_DATA); //先选择列 |
− | shiftOut(ROW_DATA); | + | shiftOut(SER, SRCK, MSBFIRST, ROW_DATA); //再送行数据 |
− | digitalWrite(RCK,HIGH); | + | digitalWrite(RCK, HIGH); |
− | } | + | } |
} | } | ||
void allOFF() { | void allOFF() { | ||
for (int i = 0; i < 8; i++) | for (int i = 0; i < 8; i++) | ||
− | screen[i] = | + | screen[i] = B0; |
} | } | ||
第 131 行: | 第 140 行: | ||
for (int i = 0; i < 8; i++) | for (int i = 0; i < 8; i++) | ||
screen[i] = B11111111; | screen[i] = B11111111; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
void loop() { | void loop() { | ||
− | + | UpdataDate(); | |
− | + | ||
− | + | ||
allOFF(); | allOFF(); | ||
} | } | ||
− | void | + | void UpdataDate() { |
− | { | + | if (animationIndex < animationFrames) { |
− | + | for (int i = 0; i < 64; i++) { | |
− | + | brightnesses[i] = (animation[animationIndex][i / 4] >> (i % 4 * 2)) & B1; | |
− | + | screen[7-i / 8] |= (brightnesses[i] << (i % 8)) ; | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | { | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
− | + | delay(animationDelays[animationIndex]); | |
− | + | animationIndex ++; | |
+ | if (animationIndex >= animationFrames) { | ||
+ | //restart animation index | ||
+ | animationIndex = 0; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | |||
− | |||
} | } | ||
+ | |||
</pre> | </pre> |
2015年10月15日 (四) 14:18的修訂版本
創建縮圖錯誤: 檔案似乎遺失:
產品簡介
8*8點陣模塊是採用2片74HC595芯片驅動紅色8X8點陣管,只需要使用控制器3路IO口,根據點陣管動態掃描原理進行顯示,可以顯示多種圖案。
規格參數
- 供電電壓:DC5V
- 使用芯片:74HC595
- 模塊尺寸:32.5*32.5*14.7MM(長*寬*高)
- 模塊重量:10.6g
引腳說明
- 1. VCC -- Vcc(電源+5V)
- 2. GND -- Gnd(地)
- 3. SER -- 串行移位輸入
- 4. RCK -- 存儲寄存器的時序輸入
- 5. SRCK -- 移位寄存器的時序輸入
應用示例
電路連接示意圖
點陣模塊 | Arduino UNO |
VCC | +5V |
GND | GND |
SER | D10 |
RCK | D11 |
SRCK | D12 |
示例代碼
示例一:基本顯示
/************************************************** * Face * ( 8x8 Led Dot Matrix with two 74HC595 on Arduino) * * by YFROBOT ***************************************************/ #include "TimerOne.h" #include "face.h" #define ROW_DATA ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4)|(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0)) #define COL_DATA ((col[0]<<7)|(col[1]<<6)|(col[2]<<5)|(col[3]<<4)|(col[4]<<3)|(col[5]<<2)|(col[6]<<1)|(col[7]<<0)) //Pin connected to DS of 74HC595 int SER = 10; //Pin connected to ST_CP of 74HC595 int RCK = 11; //Pin connected to SH_CP of 74HC595 int SRCK = 12; int row[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; int col[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; byte screen[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; volatile byte screenRow = 0; volatile byte screenCol = 0; // A counter to know what frame we're showing int animationIndex = 0; // 8x8 Point temporary array byte brightnesses[64]; void setup() { Timer1.initialize(100); pinMode(RCK, OUTPUT); pinMode(SRCK, OUTPUT); pinMode(SER, OUTPUT); Timer1.attachInterrupt(doubleBuffer); Serial.begin(9600); } void doubleBuffer() { row[screenRow] = 0; col[screenCol] = 1; screenCol++; if (screenCol >= 8) { screenCol = 0; screenRow++; if (screenRow >= 8) { screenRow = 0; } } if ((screen[screenRow] >> screenCol) & B1 == B1) { row[screenRow] = 1; col[screenCol] = 0; digitalWrite(RCK, LOW); shiftOut(SER, SRCK, MSBFIRST, COL_DATA); //先选择列 shiftOut(SER, SRCK, MSBFIRST, ROW_DATA); //再送行数据 digitalWrite(RCK, HIGH); } } void allOFF() { for (int i = 0; i < 8; i++) screen[i] = B0; } void allON() { for (int i = 0; i < 8; i++) screen[i] = B11111111; } void loop() { UpdataDate(); allOFF(); } void UpdataDate() { if (animationIndex < animationFrames) { for (int i = 0; i < 64; i++) { brightnesses[i] = (animation[animationIndex][i / 4] >> (i % 4 * 2)) & B1; screen[7-i / 8] |= (brightnesses[i] << (i % 8)) ; } delay(animationDelays[animationIndex]); animationIndex ++; if (animationIndex >= animationFrames) { //restart animation index animationIndex = 0; } } }
程序下載地址:Face
程序運行結果:點陣模塊顯示笑臉~
點陣模塊配合按鍵模塊,做打乒乓遊戲!請移步下面網址查看:Arduino驅動8*8點陣模塊 附原理圖及一個打乒乓球的遊戲代碼
參考資料
更多建議和問題歡迎反饋至 YFRobot論壇
購買方式:YFRobot 電子工作室