本帖最后由 lxf 于 2020-8-17 13:32 编辑
目标
多块MAX7219 8*8点阵屏的使用
实验材料
Arduino UNO开发板 四块MAX7219 8*8点阵屏 配套USB数据线 配套杜邦线若干 Arduino IDE软件
内容
使用四块MAX7219 8*8点阵屏显示骰子点数5
接线方式
Arduino UNO <------> MAX7219 8*8点阵屏1(IN) 5V <------> VCC GND <------> GND 11 <------> DIN 9 <------> CS 13 <------> CLK MAX7219 8*8点阵屏1(OUT) <------> MAX7219 8*8点阵屏2(IN) VCC <------> VCC GND <------> GND DOUT <------> DIN CS <------> CS CLK <------> CLK MAX7219 8*8点阵屏2(OUT) <------> MAX7219 8*8点阵屏3(IN) VCC <------> VCC GND <------> GND DOUT <------> DIN CS <------> CS CLK <------> CLK MAX7219 8*8点阵屏3(OUT) <------> MAX7219 8*8点阵屏4(IN) VCC <------> VCC GND <------> GND DOUT <------> DIN CS <------> CS CLK <------> CLK
程序实现代码
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Max72xxPanel.h> //MAX7219点阵屏库文件
- Max72xxPanel myMatrix = Max72xxPanel(9,4,1); //CS=9,水平点阵屏为4和竖直点阵屏为1
- uint8_t LEDArray[8];
- const uint8_t A[8] PROGMEM ={0xc0,0xc0,0x00,0x1e,0x1e,0x1e,0x1e,0x00};
- const uint8_t B[8] PROGMEM ={0x00,0x1e,0x1e,0x1e,0x1e,0x00,0xc0,0xc0};
- const uint8_t C[8] PROGMEM ={0xc0,0xc0,0x00,0x1e,0x1e,0x1e,0x1e,0x00};
- const uint8_t D[8] PROGMEM ={0x00,0x1e,0x1e,0x1e,0x1e,0x00,0xc0,0xc0};
- void setup(){
- }
- void loop(){
- myMatrix.setIntensity(20); //设置MAX7219点阵屏亮度为20
- myMatrix.setRotation(0,1); //将MAX7219点阵屏屏幕序号0的角度旋转270度,根据实际情况调整
- myMatrix.setRotation(1,3); //将MAX7219点阵屏屏幕序号1的角度旋转90度,根据实际情况调整
- memcpy_P (&LEDArray, &A, 8); //数组变量A的图案显示
- for(int index_i=0; index_i<8; index_i++)
- {
- for(int index_j=0*8; index_j<0*8+8; index_j++)
- {
- if((LEDArray[index_i]&0x01)>0)
- myMatrix.drawPixel(index_j, 7-index_i,1);
- else
- myMatrix.drawPixel(index_j, 7-index_i,0);
- LEDArray[index_i] = LEDArray[index_i]>>1;
- }
- }
- myMatrix.write();
- memcpy_P (&LEDArray, &B, 8); //数组变量B的图案显示
- for(int index_i=0; index_i<8; index_i++)
- {
- for(int index_j=1*8; index_j<1*8+8; index_j++)
- {
- if((LEDArray[index_i]&0x01)>0)
- myMatrix.drawPixel(index_j, 7-index_i,1);
- else
- myMatrix.drawPixel(index_j, 7-index_i,0);
- LEDArray[index_i] = LEDArray[index_i]>>1;
- }
- }
- myMatrix.write();
- memcpy_P (&LEDArray, &C, 8); //数组变量C的图案显示
- for(int index_i=0; index_i<8; index_i++)
- {
- for(int index_j=2*8; index_j<2*8+8; index_j++)
- {
- if((LEDArray[index_i]&0x01)>0)
- myMatrix.drawPixel(index_j, 7-index_i,1);
- else
- myMatrix.drawPixel(index_j, 7-index_i,0);
- LEDArray[index_i] = LEDArray[index_i]>>1;
- }
- }
- myMatrix.write();
- memcpy_P (&LEDArray, &D, 8); //数组变量D的图案显示
- for(int index_i=0; index_i<8; index_i++)
- {
- for(int index_j=3*8; index_j<3*8+8; index_j++)
- {
- if((LEDArray[index_i]&0x01)>0)
- myMatrix.drawPixel(index_j, 7-index_i,1);
- else
- myMatrix.drawPixel(index_j, 7-index_i,0);
- LEDArray[index_i] = LEDArray[index_i]>>1;
- }
- }
- myMatrix.write();
- }
复制代码
显示结果
|