#include <Wire.h> //加载Wire通讯库
#include <LiquidCrystal_I2C.h> //加载液晶屏库
LiquidCrystal_I2C lcd(0x27, 16, 2); // 设 LCD的地址为0x27,16列2行
//显示字符
#if defined(ARDUINO) && ARDUINO >= 100//判断版本
#define printByte(args) write(args);
#else
#define printByte(args) print(args,BYTE);
#endif
//要显示的汉字编码,定义为一个数组
uint8_t code [][8] = {
{0x03, 0x1c, 0x0b, 0x06, 0x04, 0x0f, 0x02, 0x04},
{0x0f, 0x04, 0x1f, 0x04, 0x0a, 0x11, 0x00, 0x00},
{0x00, 0x04, 0x0c, 0x0e, 0x08, 0x0b, 0x1f, 0x04},
{0x0e, 0x05, 0x05, 0x07, 0x06, 0x04, 0x00, 0x00},
{0x00, 0x08, 0x18, 0x1e, 0x12, 0x16, 0x1c, 0x08},
{0x18, 0x1e, 0x12, 0x12, 0x12, 0x1e, 0x12, 0x00},
{0x18, 0x05, 0x06, 0x06, 0x05, 0x04, 0x05, 0x02},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};
void setup() {
lcd.init(); //初始化LCD
lcd.backlight(); //打开背光
}
void loop() {
for (int i = 0; i < 8; i++) {
lcd.createChar(i, code[i]); //创建新字符,将每个数组映射为一个字符,分别命名为0-7
switch (i) {
// 第二排第一个坑
case 1:
lcd.setCursor(0, i);
lcd.printByte(i);
break;
// 第一个空格占位
case 2 :
lcd.setCursor((i - 1), 0);
lcd.printByte(i);
break;
// 第二排第二个坑
case 3:
lcd.setCursor(1, 1);
lcd.printByte(i);
break;
// 第一排的坑
case 4:
lcd.setCursor(2, 0);
lcd.printByte(i);
break;
case 5:
lcd.setCursor(2, 1);
lcd.printByte(i);
break;
//第二个空格占位
default :
lcd.setCursor((i - 3), 0);
lcd.printByte(i);
break;
}
lcd.setCursor(8, 1);
}
// 移动
for (int positionCounter = 0; positionCounter < 13; positionCounter++)
{
lcd.scrollDisplayRight();
delay(900);
}
// 下次移动的延迟
delay(500);
}