3917浏览
查看: 3917|回复: 13

[进阶] 32x16 RGB LED矩阵屏幕 *进阶使用*

[复制链接]
买之前,在Df商城一看见这张图,就喜欢上了她。一见钟情!

32x16 RGB LED矩阵屏幕 *进阶使用*图1

不错,不错。

    言归正传:首先通过DF官网学习一下如何使用。https://wiki.dfrobot.com.cn/_SKU_DFR0471_32x16_RGB_LED_Matrix_-_6mm_pitch
【第一关】 按照引脚说明连接好硬件
    看看下图就知,有多让人烦:
32x16 RGB LED矩阵屏幕 *进阶使用*图2

还有这个:

32x16 RGB LED矩阵屏幕 *进阶使用*图3

一定要擦亮眼睛,仔细再仔细,我错了好几次(哭)

32x16 RGB LED矩阵屏幕 *进阶使用*图4

【第二关】安装所需库文件(这个简单),但我还研究了半天“如何安装”!!!!!

【第三关】显示内容

  教程里给了两个“样例代码”,很好!一个劲的刷屏,又是圆,又是方,变换颜色,显示英文、数字,好看!

  重点来了,汉字了,怎么没有如何显示汉字???

【第四关】显示一个汉字

点阵屏,当然是一个点一个点去点亮,把汉字取模。如“宋”:{0x12 ,0x10 ,0x9 ,0x10 ,0x9 ,0x20 ,0x7f ,0xfe ,0x40 ,0x2 ,0x80 ,0x14 ,0x1f ,0xf8 ,0x10 ,0x10 ,0x11 ,0x10 ,0x11 ,0x10 ,0x11 ,0x90 ,0x12 ,0x90 ,0x12 ,0x90 ,0x4 ,0x84 ,0x8 ,0x84 ,0x70 ,0x7c}

32x16 RGB LED矩阵屏幕 *进阶使用*图5

[/url]
  1. <blockquote> #include <Adafruit_GFX.h>   // Core graphics library
复制代码


32x16 RGB LED矩阵屏幕 *进阶使用*图6

【第五关】显示两个汉字


  1. <blockquote> #include <Adafruit_GFX.h>   // Core graphics library
复制代码


32x16 RGB LED矩阵屏幕 *进阶使用*图7

(手机拍出来这个效果……)

【第六关】一个汉字走起来


  1. int str[1][32]={0x2 ,0x0 ,0x1 ,0x0 ,0x7f ,0xfe ,0x40 ,0x2 ,0x81 ,0x4 ,0x1 ,0x0 ,0x1 ,0x4 ,0xff ,0xfe ,0x3 ,0x80 ,0x5 ,0x40 ,0x9 ,0x30 ,0x11 ,0xe ,0x21 ,0x4 ,0x41 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0};
  2. int ma[8]={128,64,32,16,8,4,2,1};
  3. void led3(){
  4.   int i,j,a,n,m;
  5.   n=0;
  6. for(m=31;m>=-15;m--){
  7. for(i=0;i<32;i++)
  8.   {
  9.     for(j=0;j<8;j++){
  10.       a=(str[0][i]&ma[j])>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
  11.       if(a==1){//对应位为1,点亮
  12.           matrix.drawPixel(n+m,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  13.       }
  14.       n=n+1;
  15.       if(n==16){//16*16每过16列,换行,列号从0开始
  16.           n=0;
  17.       }
  18.       
  19.     }
  20.    }
  21.    delay(100);
  22.    matrix.fillScreen(matrix.Color333(0, 0, 0));
  23. }
  24. }
复制代码


32x16 RGB LED矩阵屏幕 *进阶使用*图832x16 RGB LED矩阵屏幕 *进阶使用*图9

【第七关】多个汉字走起来



  1. int num=7;
  2. int str[7][32]={{0x2 ,0x0 ,0x1 ,0x0 ,0x7f ,0xfe ,0x40 ,0x2 ,0x81 ,0x4 ,0x1 ,0x0 ,0x1 ,0x4 ,0xff ,0xfe ,0x3 ,0x80 ,0x5 ,0x40 ,0x9 ,0x30 ,0x11 ,0xe ,0x21 ,0x4 ,0x41 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0},
  3. {0x00,0x00,0x08,0x20,0x04,0x40,0x7f,0xfc,0x01,0x00,0x3f,0xfc,0x01,0x00,0xff,0xfe,0x01,0x00,0x7f,0xfe,0x03,0x80,0x06,0x40,0x18,0x30,0x60,0x0c,0x00,0x00,0x00,0x00},
  4. {0x00,0x00,0x10,0x40,0x10,0x40,0x17,0xfc,0x20,0x40,0x20,0x40,0x67,0xfe,0x60,0x00,0x20,0x40,0x20,0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制)对应01000101(二进制),一位一位取
  18.       if(a==1&&n+m+k*16>=0&&n+m+k*16<=31){//对应位为1,点亮
  19.           matrix.drawPixel(n+m+k*16,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  20.        }
  21.       }
  22.       n=n+1;
  23.       if(n==16){//16*16每过16列,换行,列号从0开始
  24.           n=0;
  25.       }
  26.       
  27.     }
  28.    }
  29.    delay(100);
  30.    matrix.fillScreen(matrix.Color333(0, 0, 0));
  31. }
  32. }
复制代码

最终显示内容,就不给看图片,你可以自己测试一下!



还有个倒计时牌:


  1. void time1(int a,int b){//a为倒计时初如值,本例程最大为100,b为每次延时时间,单位毫秒。
  2.   int i;
  3.   i=a;
  4.   while(1){
  5.   i=i-1;
  6.   // draw some text!
  7.   matrix.setCursor(5, 0);   // start at top left, with one pixel of spacing
  8.   matrix.setTextSize(2);    // size 1 == 8 pixels high
  9.   char output[7] = {0};
  10.   sprintf(output,"%d",i);
  11.   // print each letter with a rainbow color
  12.   matrix.setTextColor(matrix.Color333(3,6,3));
  13.   matrix.print(output);
  14. if(i==0){
  15.   i=a;
  16. }
  17.   delay(b);
  18.   matrix.fillScreen(matrix.Color333(0, 0, 0));
  19.   }
  20.    
  21. }
复制代码



【完整代码】
  1. /***************************************************
  2. *
  3. * For 32x16 RGB LED matrix.
  4. *
  5. * @author lg.gang
  6. * @version  V1.0
  7. * @date  2016-10-28
  8. *
  9. * GNU Lesser General Public License.
  10. * See <http://www.gnu.org/licenses/> for details.
  11. * All above must be included in any redistribution
  12. * ****************************************************/
  13. #include <Adafruit_GFX.h>   // Core graphics library
  14. #include <RGBmatrixPanel.h> // Hardware-specific library
  15. #define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
  16. #define LAT A3
  17. #define OE  9
  18. #define A   A0
  19. #define B   A1
  20. #define C   A2
  21. RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
  22. //http://www.lixin.me/wordmodel/此网站可汉字取字模,也可用Mind+通过扩展添加oled,显示汉字,在“自动生成”处看此汉字字模
  23. int num=7;
  24. int str[7][32]={{0x2 ,0x0 ,0x1 ,0x0 ,0x7f ,0xfe ,0x40 ,0x2 ,0x81 ,0x4 ,0x1 ,0x0 ,0x1 ,0x4 ,0xff ,0xfe ,0x3 ,0x80 ,0x5 ,0x40 ,0x9 ,0x30 ,0x11 ,0xe ,0x21 ,0x4 ,0x41 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0},
  25. {0x00,0x00,0x08,0x20,0x04,0x40,0x7f,0xfc,0x01,0x00,0x3f,0xfc,0x01,0x00,0xff,0xfe,0x01,0x00,0x7f,0xfe,0x03,0x80,0x06,0x40,0x18,0x30,0x60,0x0c,0x00,0x00,0x00,0x00},
  26. {0x00,0x00,0x10,0x40,0x10,0x40,0x17,0xfc,0x20,0x40,0x20,0x40,0x67,0xfe,0x60,0x00,0x20,0x40,0x20,0x40,0x27,0xfc,0x20,0x40,0x20,0x40,0x27,0xfe,0x00,0x00,0x00,0x00},
  27. {0x1 ,0x0 ,0x40 ,0x84 ,0x2f ,0xfe ,0x0 ,0x80 ,0x1 ,0x0 ,0x1 ,0x10 ,0xe2 ,0x10 ,0x27 ,0xe0 ,0x20 ,0x48 ,0x20 ,0x48 ,0x20 ,0x90 ,0x25 ,0x20 ,0x2a ,0x50 ,0x30 ,0x88 ,0x23 ,0x4 ,0xc ,0x4},
  28. {0x12 ,0x10 ,0x9 ,0x10 ,0x9 ,0x20 ,0x7f ,0xfe ,0x40 ,0x2 ,0x80 ,0x14 ,0x1f ,0xf8 ,0x10 ,0x10 ,0x11 ,0x10 ,0x11 ,0x10 ,0x11 ,0x90 ,0x12 ,0x90 ,0x12 ,0x90 ,0x4 ,0x84 ,0x8 ,0x84 ,0x70 ,0x7c},
  29. {0x0 ,0x0 ,0x8 ,0x18 ,0x7b ,0xe0 ,0x48 ,0x40 ,0x48 ,0x48 ,0x4f ,0xfc ,0x79 ,0x50 ,0x49 ,0x54 ,0x4f ,0xfe ,0x79 ,0x50 ,0x49 ,0x50 ,0x49 ,0x50 ,0x4f ,0xfc ,0x78 ,0x40 ,0x48 ,0x50 ,0x3 ,0xf8},
  30. {0x0 ,0x0 ,0x7f ,0xf8 ,0x0 ,0x10 ,0x0 ,0x20 ,0x0 ,0x40 ,0x1 ,0x80 ,0x1 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0 ,0x1 ,0x0 ,0x5 ,0x0 ,0x2 ,0x0}};
  31. //int ma[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
  32. int ma[8]={128,64,32,16,8,4,2,1};
  33. void setup() {
  34.   Serial.begin(9600);
  35.   matrix.begin();
  36. }
  37. void loop() {
  38.   // draw a pixel in solid white
  39.   //matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
  40.   //delay(500);
  41.   // fix the screen with green
  42.   //matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 7, 0));
  43. // delay(500);
  44.   // draw a box in yellow
  45. // matrix.drawRect(0, 0, 32, 16, matrix.Color333(7, 7, 0));
  46. // delay(500);
  47.   
  48.   // draw an 'X' in red
  49. // matrix.drawLine(0, 0, 31, 15, matrix.Color333(7, 0, 0));
  50. // matrix.drawLine(31, 0, 0, 15, matrix.Color333(7, 0, 0));
  51.   //delay(500);
  52.   
  53.   // draw a blue circle
  54. //  matrix.drawCircle(7, 7, 7, matrix.Color333(0, 0, 7));
  55.   //delay(500);
  56.   
  57.   // fill a violet circle
  58. // matrix.fillCircle(23, 7, 7, matrix.Color333(7, 0, 7));
  59.   //delay(500);
  60.   
  61.   // fill the screen with 'black'
  62.   matrix.fillScreen(matrix.Color333(0, 0, 0));
  63.    led3();
  64.   //time1(100,1000);
  65.   delay(3000);
  66. }
  67. void led1(){
  68.   int i,j,a,n;
  69.   n=0;
  70. for(i=0;i<32;i++)
  71.   {
  72.     for(j=0;j<8;j++){
  73.       a=(str[0][i]&ma[j])>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
  74.       if(a==1){//对应位为1,点亮
  75.           matrix.drawPixel(n,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  76.       }
  77.       n=n+1;
  78.       if(n==16){//16*16每过16列,换行,列号从0开始
  79.           n=0;
  80.       }
  81.       delay(10);
  82.     }
  83.    }
  84. }
  85. void led2(){
  86.   int i,j,a,n;
  87.   n=0;
  88. for(i=0;i<32;i++)
  89.   {
  90.     for(j=0;j<8;j++){
  91.       a=(str[0][i]&ma[j])>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
  92.       if(a==1){//对应位为1,点亮
  93.           matrix.drawPixel(n,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  94.       }
  95.       n=n+1;
  96.       if(n==16){//16*16每过16列,换行,列号从0开始
  97.           n=0;
  98.       }
  99.       delay(10);
  100.     }
  101.    }
  102.   n=0;
  103. for(i=0;i<32;i++)
  104.   {
  105.     for(j=0;j<8;j++){
  106.       a=(str[1][i]&ma[j])>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
  107.       if(a==1){//对应位为1,点亮
  108.           matrix.drawPixel(n+17,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  109.       }
  110.       n=n+1;
  111.       if(n==16){//16*16每过16列,换行,列号从0开始
  112.           n=0;
  113.       }
  114.       delay(10);
  115.      
  116.     }
  117.      
  118.    }
  119. }
  120. void led3(){
  121.   int i,j,a,n,m;
  122.   n=0;
  123. for(m=31;m>=-15;m--){
  124. for(i=0;i<32;i++)
  125.   {
  126.     for(j=0;j<8;j++){
  127.       a=(str[0][i]&ma[j])>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
  128.       if(a==1){//对应位为1,点亮
  129.           matrix.drawPixel(n+m,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  130.       }
  131.       n=n+1;
  132.       if(n==16){//16*16每过16列,换行,列号从0开始
  133.           n=0;
  134.       }
  135.       
  136.     }
  137.    }
  138.    delay(100);
  139.    matrix.fillScreen(matrix.Color333(0, 0, 0));
  140. }
  141. }
  142. void led4(){
  143.   int i,j,a,n,m,k;
  144.   n=0;
  145. for(m=31;m>=-num*16;m--){
  146. for(i=0;i<32;i++)
  147.   {
  148.     for(j=0;j<8;j++){
  149.       for(k=0;k<num;k++){
  150.       a=(str[k][i]&ma[j])>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
  151.       if(a==1&&n+m+k*16>=0&&n+m+k*16<=31){//对应位为1,点亮
  152.           matrix.drawPixel(n+m+k*16,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
  153.        }
  154.       }
  155.       n=n+1;
  156.       if(n==16){//16*16每过16列,换行,列号从0开始
  157.           n=0;
  158.       }
  159.       
  160.     }
  161.    }
  162.    delay(100);
  163.    matrix.fillScreen(matrix.Color333(0, 0, 0));
  164. }
  165. }
  166. void time1(int a,int b){
  167.   int i;
  168.   i=a;
  169.   while(1){
  170.   i=i-1;
  171.   // draw some text!
  172.   matrix.setCursor(5, 0);   // start at top left, with one pixel of spacing
  173.   matrix.setTextSize(2);    // size 1 == 8 pixels high
  174.   char output[7] = {0};
  175.   sprintf(output,"%d",i);
  176.   // print each letter with a rainbow color
  177.   matrix.setTextColor(matrix.Color333(3,6,3));
  178.   matrix.print(output);
  179. if(i==0){
  180.   i=a;
  181. }
  182.   delay(b);
  183.   matrix.fillScreen(matrix.Color333(0, 0, 0));
  184.   }
  185.    
  186. }
复制代码


201908012343546950.png

汤果  初级技神

发表于 2019-8-2 07:35:58

效果是挺好的,但是用起来看上去好麻烦啊~
回复

使用道具 举报

远眺星空  学徒

发表于 2019-8-2 10:34:14

显示一个静态汉字时,一直报错无法编译。
回复

使用道具 举报

云天  初级技神
 楼主|

发表于 2019-8-2 23:04:40

安装库文件了吗?上面“维库"有介绍
回复

使用道具 举报

gada888  版主

发表于 2019-8-6 22:08:45

挺有意思的
回复

使用道具 举报

熹宝快睡觉  见习技师

发表于 2019-8-8 16:33:33

很有意思   攒点东西搞一个
回复

使用道具 举报

云天  初级技神
 楼主|

发表于 2021-8-18 22:22:16

远眺星空 发表于 2019-8-2 10:34
显示一个静态汉字时,一直报错无法编译。

确实有些问题,已修正!
回复

使用道具 举报

云天  初级技神
 楼主|

发表于 2021-8-18 22:26:09

#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

void setup() {
  Serial.begin(9600);
  matrix.begin();
}

void loop() {

   led1();
   //led2();
   //led3();
  //time1(100,1000);
  delay(3000);

}

void led1()
{
#……
}
回复

使用道具 举报

云天  初级技神
 楼主|

发表于 2021-8-18 22:51:00

报错Adafruit_I2CDevice.h找不到

解决方法:安装库Adafruit_BusIO即可成功编译
1、管理库搜索BusIO
2、安装
3、解决!!!!!!
回复

使用道具 举报

大胆的去做  见习技师

发表于 2022-3-16 10:50:03

这个做完了谁要是想表白直接租给他正好
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-3-16 18:41:26

6666666666666666666
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-3-16 18:42:44

厉害厉害
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-3-16 18:43:47

赞赞赞赞赞
回复

使用道具 举报

赤星三春牛!  初级技神

发表于 2022-3-16 18:44:49

呵呵呵呵
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail