UNO直接驱动LED点阵
本帖最后由 ttyp 于 2012-11-25 10:28 编辑看很多人玩点阵,LZ心痒,也买了一个。可惜没玩过,买错了,买了一个(红绿)双色点阵,有24个脚,而手头也没有2560,UNO端口太少了,后来偶然机会,知道模拟口也可以当作数字口用的,A0-A4对于端口号是14-18.
问题又来了,后来问店主要双色点阵的资料,店主居然说没有,连电压范围参数也没有,唯一知道的就是点阵是共阳的。LZ只能靠万用表一个个测量了,把万用表打到测量二极管一档,黑笔为负,红笔为正,依次测量,送算是测量出来了,如下图:
由于端口不够,绿色的颜色不显眼,于是只接了红色的,绿色弃用!下面是端口连接,图我就不画了。
23-PIN2
22-PIN3
20-PIN4
19-PIN5
17-PIN6
16-PIN7
14-PIN8
13-PIN9
02-PIN10
03-PIN11
05-PIN12
06-PIN13
08-A0
09-A1
11-A2
12-A3
这是代码:
/*
* Show messages on an 8x8 led matrix,
* scrolling from right to left.
*
* Uses FrequencyTimer2 library to
* constantly run an interrupt routine
* at a specified frequency. This
* refreshes the display without the
* main loop having to do anything.
*
*/
#include <MsTimer2.h>
#define SPACE { \
{0, 0, 0, 0, 0, 0, 0, 0},\
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}
#define H { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}\
}
#define E{ \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}\
}
#define L { \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}\
}
#define O { \
{0, 0, 0, 1, 1, 0, 0, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 0, 0, 1, 1, 0, 0, 0}\
}
byte col = 0;
byte leds;
// pin on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins= {17,15,13,11,9,7,5,3,2,4,6,8,10,12,14,16};;
// col of leds = pin yy on led matrix
int cols = {pins, pins, pins, pins, pins, pins, pins, pins};
// row of leds = pin yy on led matrix
int rows = {pins, pins, pins, pins, pins, pins, pins, pins};
const int numPatterns = 6;
byte patterns = {
H,E,L,L,O,SPACE
};
int pattern = 0;
void setup() {
// sets the pins as output
for (int i = 0; i < 16; i++) {
pinMode(pins, OUTPUT);
}
// set up cols and rows
for (int i = 1; i <= 8; i++) {
digitalWrite(cols, LOW);
}
for (int i = 1; i <= 8; i++) {
digitalWrite(rows, LOW);
}
clearLeds();
MsTimer2::set(1, display); // 500ms period
MsTimer2::start();
setPattern(pattern);
}
void loop() {
pattern = ++pattern % numPatterns;
slidePattern(pattern, 300);
}
void clearLeds() {
// Clear display array
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds = 0;
}
}
}
void setPattern(int pattern) {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
leds = patterns;
}
}
}
void slidePattern(int pattern, int del) {
for (int l = 0; l < 8; l++) {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 8; j++) {
leds = leds;
}
}
for (int j = 0; j < 8; j++) {
leds = patterns;
}
delay(del);
}
}
// Interrupt routine
void display() {
digitalWrite(cols, LOW);// Turn whole previous column off
col++;
if (col == 8) {
col = 0;
}
for (int row = 0; row < 8; row++) {
if (leds == 1) {
digitalWrite(rows, LOW);// Turn on this led
}
else {
digitalWrite(rows, HIGH); // Turn off this led
}
}
digitalWrite(cols, HIGH); // Turn whole column on at once (for equal lighting times)
}
这是效果,实际为HELLO向左滚动!!
这是我买的点阵
这是我参考的链接:http://arduino.cc/playground/Main/DirectDriveLEDMatrix
由于它使用的库太老了,我把它使用的定时库改成了mstimer2
800K的图片都无法提交?说上传太大? ttyp 发表于 2012-11-25 10:22 static/image/common/back.gif
800K的图片都无法提交?说上传太大?
额。。图片限制为400K了~~~ 点阵屏的教程,论坛还没有呢,顶楼主! smfox10 发表于 2012-11-25 16:03 static/image/common/back.gif
点阵屏的教程,论坛还没有呢,顶楼主!
有的,不过是用芯片驱动的,还有5*5的教程 这段时间比较流行点阵屏啊。。。{:soso_e102:} ttyp 发表于 2012-11-25 16:27 static/image/common/back.gif
有的,不过是用芯片驱动的,还有5*5的教程
我有写595x2驱动点阵。。不过沉了{:3_60:}
http://www.geek-workshop.com/thread-2570-1-1.html 点阵屏一般都是用74595芯片或者是DM163或者是....等其他的芯片来专门驱动,直接驱动都IO口太吃力了! Randy 发表于 2012-11-26 09:30 static/image/common/back.gif
点阵屏一般都是用74595芯片或者是DM163或者是....等其他的芯片来专门驱动,直接驱动都IO口太吃力了!
没有芯片只能直驱了,再说用最小系统驱动也不错啊,可以做很多东西,有时还省芯片和布线 ttyp 发表于 2012-11-26 10:03 static/image/common/back.gif
没有芯片只能直驱了,再说用最小系统驱动也不错啊,可以做很多东西,有时还省芯片和布线
在没有其他多余的驱动IC情况下,考虑成本和方便的问题,直驱是OK的,但是这样有时候会很不稳定的哦!做产品的话还是建议选用专驱动IC!DIY的话就无所谓了。爱怎么玩就怎么玩!哈哈! Randy 发表于 2012-11-26 10:10 static/image/common/back.gif
在没有其他多余的驱动IC情况下,考虑成本和方便的问题,直驱是OK的,但是这样有时候会很不稳定的哦!做产 ...
不稳定是指是么?没接限流电阻?开始接了的,亮度很暗,后来听说led打开的时间很短是不会有问题的 ttyp 发表于 2012-11-26 10:34 static/image/common/back.gif
不稳定是指是么?没接限流电阻?开始接了的,亮度很暗,后来听说led打开的时间很短是不会有问题的
开机时和开机后都会有电流波动,而且是直接主控过来的。接不接都没什么,我说了不是产品考虑的不多,能用就好!哈哈! “由于它使用的库太老了,我把它使用的定时库改成了mstimer2”请教楼住这句话意思 jinhao 发表于 2012-11-26 23:15 static/image/common/back.gif
“由于它使用的库太老了,我把它使用的定时库改成了mstimer2”请教楼住这句话意思
就是换了一个定时库啊,原链接的库太老了,1.0.2上编译不通过 我使用了您的程序 显示错误
sketch_apr22c.cpp: In function 'void setup()':
sketch_apr22c:32: error: 'MsTimer2' has not been declared
sketch_apr22c:33: error: 'MsTimer2' has not been declared
是怎么回事啊 本人菜鸟 急需这方面的知识 求高手加我QQ670096828指导我下感激不尽
页:
[1]