本帖最后由 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[8][8];
- // pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
- int pins[17]= {17,15,13,11,9,7,5,3,2,4,6,8,10,12,14,16};;
- // col[xx] of leds = pin yy on led matrix
- int cols[8] = {pins[0], pins[1], pins[2], pins[3], pins[4], pins[5], pins[6], pins[7]};
- // row[xx] of leds = pin yy on led matrix
- int rows[8] = {pins[8], pins[9], pins[10], pins[11], pins[12], pins[13], pins[14], pins[15]};
- const int numPatterns = 6;
- byte patterns[numPatterns][8][8] = {
- 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[i], OUTPUT);
- }
- // set up cols and rows
- for (int i = 1; i <= 8; i++) {
- digitalWrite(cols[i - 1], LOW);
- }
- for (int i = 1; i <= 8; i++) {
- digitalWrite(rows[i - 1], 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[i][j] = 0;
- }
- }
- }
- void setPattern(int pattern) {
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- leds[i][j] = patterns[pattern][i][j];
- }
- }
- }
- 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[j][i] = leds[j][i+1];
- }
- }
- for (int j = 0; j < 8; j++) {
- leds[j][7] = patterns[pattern][j][0 + l];
- }
- delay(del);
- }
- }
- // Interrupt routine
- void display() {
- digitalWrite(cols[col], LOW); // Turn whole previous column off
- col++;
- if (col == 8) {
- col = 0;
- }
- for (int row = 0; row < 8; row++) {
- if (leds[7-col][row] == 1) {
- digitalWrite(rows[row], LOW); // Turn on this led
- }
- else {
- digitalWrite(rows[row], HIGH); // Turn off this led
- }
- }
- digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
- }
复制代码
这是效果,实际为HELLO向左滚动!!
这是我买的点阵
这是我参考的链接:http://arduino.cc/playground/Main/DirectDriveLEDMatrix
由于它使用的库太老了,我把它使用的定时库改成了mstimer2
|