//8*8LED点阵模块显示实验
//点阵显示上下左右箭头、三种表情和三种爱心
#include <LedControl.h>
//Arduino UNO SPI引脚:D10(CS)、D11(MOSI)、D12(MISO)、D13(SCLK)
int DIN = 10;//SPI模式,MOSI主设备输出,从设备输入
int CS = 9;//SPI模式,CS片选
int CLK = 8;//SPI模式,CLK
//面部表情
byte smile[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};//微笑
byte neutral[8] = {0x3C, 0x42, 0xA5, 0x81, 0xBD, 0x81, 0x42, 0x3C};//中性
byte sad[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};//悲伤
//实心箭头
byte Front[8] = {0x08, 0x1c, 0x3e, 0x7f, 0x1c, 0x1c, 0x1c, 0x1c}; //向上箭头↑
byte back[8] = {0x1c, 0x1c, 0x1c, 0x1c, 0x7f, 0x3e, 0x1c, 0x08}; //向下箭头↓
byte left[8] = {0x10, 0x30, 0x7f, 0xff, 0x7f, 0x30, 0x10, 0x00}; //向左箭头←
byte right[8] = {0x08, 0x0c, 0xfe, 0xff, 0xfe, 0x0c, 0x08, 0x00}; //向右箭头→
//爱心
byte heart[8] = {0x00, 0x76, 0x89, 0x81, 0x81, 0x42, 0x24, 0x18}; //空❤
byte heart1[8] = {0x00, 0x00, 0x24, 0x7E, 0x7E, 0x3C, 0x18, 0x00}; //小❤
byte heart2[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18}; //大❤
LedControl lc = LedControl(DIN, CLK, CS, 0);//新建一个类对象
void setup()
{
lc.shutdown(0, false); //初始化时设置点阵为正常使用模式
lc.setIntensity(0, 1); //设置亮度值,范围0~15
lc.clearDisplay(0); //点阵清屏
}
void loop()
{
//显示箭头
printByte(Front);
delay(2000);
printByte(back);
delay(2000);
printByte(left);
delay(2000);
printByte(right);
delay(2000);
//显示表情
printByte(smile);
delay(2000);
printByte(neutral);
delay(2000);
printByte(sad);
delay(2000);
//显示❤
printByte(heart);
delay(2000);
printByte(heart1);
delay(2000);
printByte(heart2);
delay(2000);
}
void printByte(byte character [])
{
int i = 0;
for (i = 0; i < 8; i++)
{
lc.setRow(0, i, character[i]);//设置点阵单行8个LED状态,每行数据用16进制表示
}
}