云天 发表于 2019-8-2 00:16:59

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

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

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

还有这个:

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

【第二关】安装所需库文件(这个简单),但我还研究了半天“如何安装”!!!!!
【第三关】显示内容
教程里给了两个“样例代码”,很好!一个劲的刷屏,又是圆,又是方,变换颜色,显示英文、数字,好看!
重点来了,汉字了,怎么没有如何显示汉字???
【第四关】显示一个汉字
点阵屏,当然是一个点一个点去点亮,把汉字取模。如“宋”:{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}

有个网站,可以方便获取http://www.lixin.me/wordmodel/<blockquote> #include <Adafruit_GFX.h>   // Core graphics library


【第五关】显示两个汉字

<blockquote> #include <Adafruit_GFX.h>   // Core graphics library


(手机拍出来这个效果……)
【第六关】一个汉字走起来


int str={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};
int ma={128,64,32,16,8,4,2,1};

void led3(){
int i,j,a,n,m;
n=0;
for(m=31;m>=-15;m--){
for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1){//对应位为1,点亮
          matrix.drawPixel(n+m,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      
    }
   }
   delay(100);
   matrix.fillScreen(matrix.Color333(0, 0, 0));
}
}


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



int num=7;
int str={{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},
{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},
{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},
{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},{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},
{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},
{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}};

int ma={128,64,32,16,8,4,2,1};


void led4(){
int i,j,a,n,m,k;
n=0;
for(m=31;m>=-num*16;m--){
for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      for(k=0;k<num;k++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1&&n+m+k*16>=0&&n+m+k*16<=31){//对应位为1,点亮
          matrix.drawPixel(n+m+k*16,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
       }
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      
    }
   }
   delay(100);
   matrix.fillScreen(matrix.Color333(0, 0, 0));
}
}

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


还有个倒计时牌:

void time1(int a,int b){//a为倒计时初如值,本例程最大为100,b为每次延时时间,单位毫秒。
int i;
i=a;
while(1){
i=i-1;
// draw some text!
matrix.setCursor(5, 0);   // start at top left, with one pixel of spacing
matrix.setTextSize(2);    // size 1 == 8 pixels high
char output = {0};
sprintf(output,"%d",i);
// print each letter with a rainbow color
matrix.setTextColor(matrix.Color333(3,6,3));
matrix.print(output);
if(i==0){
i=a;
}
delay(b);
matrix.fillScreen(matrix.Color333(0, 0, 0));
}
   
}



【完整代码】/***************************************************
*
* For 32x16 RGB LED matrix.
*
* @author lg.gang
* @versionV1.0
* @date2016-10-28
*
* GNU Lesser General Public License.
* See <http://www.gnu.org/licenses/> for details.
* All above must be included in any redistribution
* ****************************************************/

#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 OE9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
//http://www.lixin.me/wordmodel/此网站可汉字取字模,也可用Mind+通过扩展添加oled,显示汉字,在“自动生成”处看此汉字字模
int num=7;
int str={{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},
{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},
{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},
{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},
{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},
{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},
{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}};
//int ma[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
int ma={128,64,32,16,8,4,2,1};





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

void loop() {

// draw a pixel in solid white
//matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
//delay(500);

// fix the screen with green
//matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 7, 0));
// delay(500);

// draw a box in yellow
// matrix.drawRect(0, 0, 32, 16, matrix.Color333(7, 7, 0));
// delay(500);

// draw an 'X' in red
// matrix.drawLine(0, 0, 31, 15, matrix.Color333(7, 0, 0));
// matrix.drawLine(31, 0, 0, 15, matrix.Color333(7, 0, 0));
//delay(500);

// draw a blue circle
//matrix.drawCircle(7, 7, 7, matrix.Color333(0, 0, 7));
//delay(500);

// fill a violet circle
// matrix.fillCircle(23, 7, 7, matrix.Color333(7, 0, 7));
//delay(500);

// fill the screen with 'black'
matrix.fillScreen(matrix.Color333(0, 0, 0));

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

}

void led1(){
int i,j,a,n;
n=0;

for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1){//对应位为1,点亮
          matrix.drawPixel(n,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      delay(10);
    }
   }
}



void led2(){
int i,j,a,n;
n=0;

for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1){//对应位为1,点亮
          matrix.drawPixel(n,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      delay(10);
    }
   }
n=0;
for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1){//对应位为1,点亮
          matrix.drawPixel(n+17,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      delay(10);
   
    }
   
   }

}

void led3(){
int i,j,a,n,m;
n=0;
for(m=31;m>=-15;m--){
for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1){//对应位为1,点亮
          matrix.drawPixel(n+m,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      
    }
   }
   delay(100);
   matrix.fillScreen(matrix.Color333(0, 0, 0));
}
}


void led4(){
int i,j,a,n,m,k;
n=0;
for(m=31;m>=-num*16;m--){
for(i=0;i<32;i++)
{
    for(j=0;j<8;j++){
      for(k=0;k<num;k++){
      a=(str&ma)>>(7-j);//16进制数,按位取,如0x45(十六进制)对应01000101(二进制),一位一位取
      if(a==1&&n+m+k*16>=0&&n+m+k*16<=31){//对应位为1,点亮
          matrix.drawPixel(n+m+k*16,i/2, matrix.Color333(7, 7, 7)); //n为列号,因为这里一个十六进制数为8位,两个为一行,所以行号为i/2
       }
      }
      n=n+1;
      if(n==16){//16*16每过16列,换行,列号从0开始
          n=0;
      }
      
    }
   }
   delay(100);
   matrix.fillScreen(matrix.Color333(0, 0, 0));
}
}
void time1(int a,int b){
int i;
i=a;
while(1){
i=i-1;
// draw some text!
matrix.setCursor(5, 0);   // start at top left, with one pixel of spacing
matrix.setTextSize(2);    // size 1 == 8 pixels high
char output = {0};
sprintf(output,"%d",i);
// print each letter with a rainbow color
matrix.setTextColor(matrix.Color333(3,6,3));
matrix.print(output);
if(i==0){
i=a;
}
delay(b);
matrix.fillScreen(matrix.Color333(0, 0, 0));
}
   
}

汤果 发表于 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 OE9
#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

呵呵呵呵
页: [1]
查看完整版本: 32x16 RGB LED矩阵屏幕 *进阶使用*