查看: 1732|回复: 16
|
Arduino 和8x8 dot matrix 问题
[复制链接]
|
|
Uploaded with ImageShack.us
- const char matrix[][8] = {
- {0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,0x00}, //1
-
- };
- int latchPin_col = 9 ; //Pin connected to SH_CP of 74HC595
- int clockPin_col = 10 ;//Pin connected to DS of 74HC595
- int dataPin_col = 8;
- <span style="line-height: 1.5;">int latchPin_row = 5; </span>//Pin connected to SH_CP of 74HC595
- int clockPin_row = 6; //Pin connected to DS of 74HC595
- int dataPin_row = 7;
- int x,y;
- void setup() //set pins to output because they are addressed in the main loop
- pinMode(latchPin_col, OUTPUT);
- pinMode(clockPin_col, OUTPUT);
- pinMode(dataPin_col, OUTPUT);
- pinMode(latchPin_row, OUTPUT);
- pinMode(clockPin_row, OUTPUT);
- pinMode(dataPin_row, OUTPUT);
- }
- void loop()
- {
- for (int row = 0; row < 8; row++)
- {
- int rowbit = 1 << row;
- digitalWrite(latchPin_row, LOW); //Hold latchPin LOW for as long as we're transmitting data
- shiftOut(dataPin_row, clockPin_row, MSBFIRST, rowbit); //Transmit data
- digitalWrite(latchPin_row, LOW); //Hold latchPin LOW for as long as we're transmitting dat
- digitalWrite(latchPin_col, LOW);
- shiftOut(dataPin_col, clockPin_col, MSBFIRST, matrix[0][row]);
- digitalWrite(latchPin_col, LOW);
- digitalWrite(latchPin_col, HIGH);
- digitalWrite(latchPin_row, HIGH);
- delayMicroseconds(500);
- }
-
- }
复制代码 我做了很久,当我现在只要可以显示1号时。可是不懂为什么那个1号不能在我准确的位子。 我想是array的问题。请求大家的帮忙。谢谢
本帖最后由 wilson16 于 6-9-2013 03:44 PM 编辑
|
|
|
|
|
|
|
|
发表于 7-9-2013 07:38 PM
|
显示全部楼层
什么是1号不能在我准确的位子?
建议显示4号,比较容易分析问题。
|
|
|
|
|
|
|
|
楼主 |
发表于 8-9-2013 05:12 PM
|
显示全部楼层
好不容易可以显示到一个A字。但看会去自己的programming, array很奇怪。其实我只是要做比如两个input(Active low),当第一个input1 trigger时,会显示A。如果是input2 trigger 时会显示B。大概是这样。但写到这边,不会了。 我用两个74HC595。一个col,一个给Row。
Uploaded with ImageShack.us- int latchPin = 5;
- int clockPin = 6;
- int dataPin = 4;
- int i,j;
- int row;
- int rowlatchPin = 10;
- int rowclockPin = 9;
- int rowdataPin = 8;
- byte colMatrix[][1] = {
- {0x00},
- {0x3f},
- {0x44},
- {0x44},
- {0x44},
- {0x44},
- {0x3f},
- {0x00}
- };
- void setup()
- {
- pinMode(latchPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
-
- pinMode(rowlatchPin, OUTPUT);
- pinMode(rowdataPin, OUTPUT);
- pinMode(rowclockPin, OUTPUT);
- }
-
- void loop()
- {
- for(row = 0; row <8; row++)
- {
- int rowbit= 1<<row;
- digitalWrite(rowlatchPin, LOW);
- shiftOut(rowdataPin, rowclockPin, MSBFIRST,rowbit);
-
- digitalWrite(latchPin, LOW);
-
- for(int j =7; j>=0; j--)
- {
- shiftOut(dataPin, clockPin, MSBFIRST, colMatrix[row][j]);
- }
- digitalWrite(latchPin, HIGH);
- digitalWrite(rowlatchPin, HIGH);
- delayMicroseconds(500);
- }
- }
-
复制代码 本帖最后由 wilson16 于 8-9-2013 05:21 PM 编辑
|
|
|
|
|
|
|
|
发表于 9-9-2013 10:44 AM
|
显示全部楼层
wilson16 发表于 8-9-2013 05:12 PM
好不容易可以显示到一个A字。但看会去自己的programming, array很奇怪。其实我只是要做比如两个input(Act ...
- const int buttonA = 2; // the number of the pushbutton pin
- const int buttonB = 3; // the number of the pushbutton pin
- // variables will change:
- int buttonAstate = 0; // variable for reading the pushbuttonA status
- int buttonBstate = 0; // variable for reading the pushbuttonB status
- void setup() {
-
- // initialize the pushbutton pin as an input:
- pinMode(buttonA, INPUT);
- pinMode(buttonB, INPUT);
-
- // turn on pull-up resistor
- digitalWrite(buttonA, HIGH);
- digitalWrite(buttonB, HIGH);
- }
- void loop(){
- // read the state of the pushbutton value:
- buttonAstate = digitalRead(buttonA);
- buttonBstate = digitalRead(buttonB);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is LOW:
- if (buttonAstate == LOW) {
- // do something
- }
- // check if the pushbutton is pressed.
- // if it is, the buttonState is LOW:
- if (buttonBstate == LOW) {
- // do something
- }
- }
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 9-9-2013 02:29 PM
|
显示全部楼层
西门庆33 发表于 9-9-2013 10:44 AM
谢谢你的回复。你给的也是我将会加进去的。 可是我先要解决一个问题,就是我不明白3D array的原理。目前我用的是2D array,所以只能显示一个字母。就算加进去array里,跟本loop不到。请问3D array怎样跑得?google过了,不是很明白。- #define A {0x00},{0x3f},{0x44},{0x44},{0x44},{0x44},{0x3f},{0x00}
- #define B {0x05},{0x3f},{0x44},{0x44},{0x44},{0x44},{0x3f},{0x00}
- int latchPin = 5;
- int clockPin = 6;
- int dataPin = 4;
- int i,j;
- int row;
- int rowlatchPin = 10;
- int rowclockPin = 9;
- int rowdataPin = 8;
-
- byte colMatrix[][1]={A};//PUT YOU TEXT HERE
- <span style="line-height: 1.5;">void setup() </span>
- {
- pinMode(latchPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
-
- pinMode(rowlatchPin, OUTPUT);
- pinMode(rowdataPin, OUTPUT);
- pinMode(rowclockPin, OUTPUT);
- }
-
- void loop()
- {
- update();
-
- }
-
- void update()
- {
- for(row = 0; row <8; row++)
- {
- int rowbit= 1<<row;
- digitalWrite(rowlatchPin, LOW);
- shiftOut(rowdataPin, rowclockPin, MSBFIRST,rowbit);
- digitalWrite(latchPin, LOW);
- for(int j =7; j>=0; j--)
- {
- shiftOut(dataPin, clockPin, MSBFIRST, colMatrix[row][j]);
- }
- digitalWrite(latchPin, HIGH);
- digitalWrite(rowlatchPin, HIGH);
- delayMicroseconds(500);
- }
- }
复制代码 上面的是用2D array。我要用3D array 是因为当
int numberpattern;
byte colMatrix[numberpattern][8][1]={A,B,C};
如果numberpattern=0, colMatrix[numberpattern][8][1] =='A'
如果numberpattern=1, colMatrix[numberpattern][8][1] =='B'
如果numberpattern=2, colMatrix[numberpattern][8][1] =='C'
有错的话,请纠正我吧。
|
|
|
|
|
|
|
|
发表于 9-9-2013 11:15 PM
|
显示全部楼层
wilson16 发表于 9-9-2013 02:29 PM
谢谢你的回复。你给的也是我将会加进去的。 可是我先要解决一个问题,就是我不明白3D array的原理。目前我 ...
使用single dimension array可以完全工作。比如四个字母(4x8=32)的array可以这样写
每行row乘八就是个别的字母- unsigned char colMatrix[32] =
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E,
- 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E,
- 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00,
- };
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 10-9-2013 12:04 AM
|
显示全部楼层
西门庆33 发表于 9-9-2013 11:15 PM
使用single dimension array可以完全工作。比如四个字母(4x8=32)的array可以这样写
每行row乘八就是个 ...
如果全部都在一起的话,要分开显示出来好像更难。因为要跟着input来显示那些字。 |
|
|
|
|
|
|
|
发表于 10-9-2013 09:26 AM
|
显示全部楼层
wilson16 发表于 10-9-2013 12:04 AM
如果全部都在一起的话,要分开显示出来好像更难。因为要跟着input来显示那些字。
你想得太复杂了。
这里lineNumber当着是你的字母,lineNumber为0时是第一个字母,lineNumber为1时是第二个字母,由此类推。用回你之前的代码必需加 lineNumber 乘8。 本帖最后由 西门庆33 于 10-9-2013 09:36 AM 编辑
|
|
|
|
|
|
|
|
楼主 |
发表于 12-9-2013 12:41 AM
|
显示全部楼层
西门庆33 发表于 10-9-2013 09:26 AM
你想得太复杂了。
这里lineNumber当着是你的字母,lineNumber为0时是第一个字母,lineNumber为1时是第 ...
做到半死,终于有点成果了。谢谢你的指点。
Uploaded with ImageShack.us
|
评分
-
查看全部评分
|
|
|
|
|
|
|
发表于 12-9-2013 07:35 PM
|
显示全部楼层
wilson16 发表于 12-9-2013 12:41 AM
做到半死,终于有点成果了。谢谢你的指点。
可以分享你的代码吗?
|
|
|
|
|
|
|
|
楼主 |
发表于 17-9-2013 10:46 AM
|
显示全部楼层
西门庆33 发表于 12-9-2013 07:35 PM
可以分享你的代码吗?
可以啊,给我时间整理一下下。
|
|
|
|
|
|
|
|
楼主 |
发表于 17-9-2013 07:09 PM
|
显示全部楼层
西门庆33 发表于 12-9-2013 07:35 PM
可以分享你的代码吗?
- #define UP { \
- {0x08}, \
- {0x10}, \
- {0x20}, \
- {0x40}, \
- {0x40}, \
- {0x20}, \
- {0x10}, \
- {0x08} \
- }
- #define DOWN { \
- {0x10}, \
- {0x08}, \
- {0x04}, \
- {0x02}, \
- {0x02}, \
- {0x04}, \
- {0x08}, \
- {0x10} \
- }
- #define PL1_1 { \
- {0}, \
- {0x7f}, \
- {0x48}, \
- {0x48}, \
- {0x30}, \
- {0}, \
- {0x7f}, \
- {0x01} \
- }
- #define PL1_2 { \
- {0x01}, \
- {0x01}, \
- {0x01}, \
- {0}, \
- {0x21}, \
- {0x7f}, \
- {0x01}, \
- {0} \
- }
- #define A { \
- {0}, \
- {0x3f}, \
- {0x44}, \
- {0x44}, \
- {0x44}, \
- {0x44}, \
- {0x3f}, \
- {0} \
- }
- #define B { \
- {0}, \
- {0}, \
- {0x7f}, \
- {0x49}, \
- {0x49}, \
- {0x49}, \
- {0x3e}, \
- {0} \
- }
- #define C { \
- {0}, \
- {0}, \
- {0x3E}, \
- {0x41}, \
- {0x41}, \
- {0x41}, \
- {0x22}, \
- {0} \
- }
- #define D { \
- {0}, \
- {0x7F}, \
- {0x41}, \
- {0x41}, \
- {0x41}, \
- {0x41}, \
- {0x3E}, \
- {0} \
- }
- #define SPACE { \
- {0}, \
- {0}, \
- {0}, \
- {0}, \
- {0}, \
- {0}, \
- {0}, \
- {0} \
- }
- int latchPin = 5;
- int clockPin = 6;
- int dataPin = 4;
- int latchPin1 = 12;
- int clockPin1 = 13;
- int dataPin1 = 11;
- int i,j;
- int row;
- int rowlatchPin = 10;
- int rowclockPin = 9;
- int rowdataPin = 8;
- int buttonAstate = 0; // variable for reading the pushbuttonA status
- int buttonBstate = 0; // variable for reading the pushbuttonB status
- const int buttonA = 0; // the number of the pushbutton pin
- const int buttonB = 1; // the number of the pushbutton
- int count;
- byte colMatrix1[4][16][1]={SPACE, PL1_2, D ,D};//PUT YOU TEXT HERE
- byte colMatrix2[3][16][1]={SPACE, PL1_1, B };//PUT YOU TEXT HERE
- byte colMatrix3[3][16][1]={SPACE, D, C };//PUT YOU TEXT HERE
- byte colMatrix4[3][16][1]={SPACE, B, B };//PUT YOU TEXT HERE
-
- int a;
- void setup()
- {
- pinMode(latchPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
-
- pinMode(rowlatchPin, OUTPUT);
- pinMode(rowdataPin, OUTPUT);
- pinMode(rowclockPin, OUTPUT);
-
- pinMode(latchPin1, OUTPUT);
- pinMode(dataPin1, OUTPUT);
- pinMode(clockPin1, OUTPUT);
-
-
- pinMode(buttonA, INPUT);
- pinMode(buttonB, INPUT);
-
-
- digitalWrite(buttonA, HIGH);
- digitalWrite(buttonB, HIGH);
-
- }
-
- void loop()
- {
- buttonAstate = digitalRead(buttonA);
- buttonBstate = digitalRead(buttonB);
-
-
-
- if (buttonAstate == LOW){
- for(int refreshcount=0; refreshcount<10; refreshcount++) ;
- {
- update(2);
-
- }
- }
- }
-
- else
- for(int refreshcount=0; refreshcount<10; refreshcount++)
- {
- update(0);
- }
-
-
- }
-
- void update(int count)
- {
- for(row = 0; row <8; row++)
- {i++;
- int rowbit= 1<<row;
- digitalWrite(rowlatchPin, LOW);
- shiftOut(rowdataPin, rowclockPin, MSBFIRST,rowbit);
- digitalWrite(latchPin, LOW);
- digitalWrite(latchPin1, LOW);
-
- for(int j =8; j>=0; j--)
- {
- shiftOut(dataPin, clockPin, MSBFIRST, colMatrix1[count][row][j]);
- }
- shiftOut(dataPin, clockPin, MSBFIRST, colMatrix2[count][row][j]);
- shiftOut(dataPin, clockPin, MSBFIRST, colMatrix3[count][row][j]);
- shiftOut(dataPin, clockPin, MSBFIRST, colMatrix4[count][row][j]);
- shiftOut(dataPin1, clockPin1, MSBFIRST, LED[row][j]);
-
-
- digitalWrite(latchPin, HIGH);
- digitalWrite(rowlatchPin, HIGH);
- }
- }
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 18-9-2013 09:13 AM
|
显示全部楼层
其实我写到很乱水下。 |
|
|
|
|
|
|
|
发表于 20-9-2013 10:00 PM
|
显示全部楼层
wilson16 发表于 17-9-2013 07:09 PM
谢谢分享
不能用以下方法(array)完成吗?- unsigned char colMatrix[32] =
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E,
- 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E,
- 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00,
- };
复制代码 |
|
|
|
|
|
|
|
楼主 |
发表于 20-9-2013 11:28 PM
|
显示全部楼层
西门庆33 发表于 20-9-2013 10:00 PM
谢谢分享
不能用以下方法(array)完成吗?
可以的。但我做不到。
所以就越想越复杂。
|
|
|
|
|
|
|
|
发表于 27-9-2013 10:55 PM
|
显示全部楼层
wilson16 发表于 10-9-2013 12:04 AM
如果全部都在一起的话,要分开显示出来好像更难。因为要跟着input来显示那些字。
single dimension array与two dimension array示范
使用single dimension array- const byte COL_COUNT = 8;
- const byte ROW_COUNT = 3;
-
- //array to hold the data
- unsigned char sequence[24] = {
- B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000,
- B00000001, B00000011, B00000111, B00001111, B00011111, B00111111, B01111111, B11111111,
- B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111
- };
-
- //Define which pins will be used for the shift register control
- //can be any digital pin on the Arduino
- int latchPin = 8; //Pin connected to ST_CP(pin 12) of 74HC595
- int clockPin = 12; //Pin connected to SH_CP(pin 11) of 74HC595
- int dataPin = 11; //Pin connected to DS(pin 14) of 74HC595
-
- void setup() {
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- }
-
- void loop()
- {
- for (int row = 0; row < ROW_COUNT; row++)
- {
- for (int col = 0; col < COL_COUNT; col++)
- {
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, sequence[col + row*COL_COUNT]);
- digitalWrite(latchPin, HIGH);
- delay(200);
- }
- }
- }
复制代码 使用two dimension array- const byte COL_COUNT = 8;
- const byte ROW_COUNT = 3;
-
- //array to hold the data
- unsigned char sequence[ROW_COUNT][COL_COUNT] = {
- B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000,
- B00000001, B00000011, B00000111, B00001111, B00011111, B00111111, B01111111, B11111111,
- B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111
- };
-
- //Define which pins will be used for the shift register control
- //can be any digital pin on the Arduino
- int latchPin = 8; //Pin connected to ST_CP(pin 12) of 74HC595
- int clockPin = 12; //Pin connected to SH_CP(pin 11) of 74HC595
- int dataPin = 11; //Pin connected to DS(pin 14) of 74HC595
-
- void setup() {
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- }
-
- void loop()
- {
- for (int row = 0; row < ROW_COUNT; row++)
- {
- for (int col = 0; col < COL_COUNT; col++)
- {
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, sequence[row][col]);
- digitalWrite(latchPin, HIGH);
- delay(200);
- }
- }
- }
复制代码 把shiftOut() 函数从loop()抽出,编写成单独的程序(procedure),可以随意呼叫
比如可以写成
# define A 0
# define B 1
# define C 2 等等等
然后这样呼叫
row = A; col_display();
当然这不是一个矩阵显示,你必须如你上面般加入扫描- const byte COL_COUNT = 8;
- const byte ROW_COUNT = 3;
-
- //array to hold the data
- unsigned char sequence[ROW_COUNT][COL_COUNT] = {
- B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000,
- B00000001, B00000011, B00000111, B00001111, B00011111, B00111111, B01111111, B11111111,
- B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111
- };
-
- //Define which pins will be used for the shift register control
- //can be any digital pin on the Arduino
- int latchPin = 8; //Pin connected to ST_CP(pin 12) of 74HC595
- int clockPin = 12; //Pin connected to SH_CP(pin 11) of 74HC595
- int dataPin = 11; //Pin connected to DS(pin 14) of 74HC595
-
- int row;
-
- void setup() {
- Serial.begin(9600);
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- }
-
- void loop()
- {
- row = 0; col_display();
- row = 1; col_display();
- row = 2; col_display();
- row = 1; col_display();
- row = 0; col_display();
- }
-
- void col_display()
- {
- for (int col = 0; col < COL_COUNT; col++)
- {
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, sequence[row][col]);
- digitalWrite(latchPin, HIGH);
- delay(200);
- }
- }
复制代码 如果想要使用single dimension array,把char sequence[]和shiftOut改为:
unsigned char sequence[24]
shiftOut(dataPin, clockPin, MSBFIRST, sequence[col + row*COL_COUNT]);
|
|
|
|
|
|
|
|
楼主 |
发表于 15-10-2013 01:45 PM
|
显示全部楼层
谢谢分享,我会慢慢更改和试试。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|