kylin2019 发表于 2019-9-10 20:02:03

关于LedControl库发个例子


代码也是网上找的,部分地方做了优化
4个点阵串联的。
#include <LedControl.h>

int DIN = 2;
int CS =3;
int CLK = 4;

byte e =   {0x7C, 0x7C, 0x60, 0x7C, 0x7C, 0x60, 0x7C, 0x7C}; //E
byte d =   {0x78, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x78}; //D
byte u =   {0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E}; //U
byte c =   {0x7E, 0x7E, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x7E}; //C
byte eight = {0x7E, 0x7E, 0x66, 0x7E, 0x7E, 0x66, 0x7E, 0x7E}; //8
byte s =   {0x7E, 0x7C, 0x60, 0x7C, 0x3E, 0x06, 0x3E, 0x7E}; //S
byte dot =   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18}; //.
byte o =   {0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E}; //O
byte m =   {0xE7, 0xFF, 0xFF, 0xDB, 0xDB, 0xDB, 0xC3, 0xC3}; //M
byte smile =   {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C}; //笑脸
byte neutral = {0x3C, 0x42, 0xA5, 0x81, 0xBD, 0x81, 0x42, 0x3C}; //标准脸




LedControl lc = LedControl(DIN, CLK, CS, 4);

void setup() {
    for(int index=0;index<lc.getDeviceCount();index++) {
      lc.shutdown(index, false);      //启动时,MAX72XX处于省电模式
      lc.setIntensity(index, 4);      //将亮度设置为最大值
      lc.clearDisplay(index);         //清除显示
    }
}

void loop() {
printByte(smile);//显示
delay(1000);//延时1秒
printByte(neutral);//显示标准脸
delay(1000);
}

//点阵显示函数
void printByte(byte character [])
{
int i = 0;
for (i = 0; i < 8; i++)
{
    lc.setRow(0, i, character);
    lc.setRow(1, i, character);
    lc.setRow(2, i, character);
    lc.setRow(3, i, character);
}
}
页: [1]
查看完整版本: 关于LedControl库发个例子