LiquidCrystal_i2c是一个通过i2c驱动lcd显示屏的库函数,具体使用说明如下
i2c转接芯片的型号 PCA8574
arduino R3
A05 为 SCL
A04 为 SDL
在头文件下要初始化对象
LiquidCrystal_I2C lcd(0x27,16,2);
对象名 lcd 可以任意,这关系到下面你使用方法的对象名
例如
如果 你的初始化对象名为 lcd
LiquidCrystal_I2C lcd(0x27,16,2);
lcd.init(); // 初始化lCD
如果 你的初始化对象名为 lcd1602
LiquidCrystal_I2C lcd1602(0x27,16,2);
lcd1602.init(); // 初始化lCD
LiquidCrystal_I2C lcd(0x27,16,2);
初始化对象中有三个参数,分别对应 地址、列、行
地址取决于转接板上A0 A1 A2 的连接
悬空即拔掉跳线帽
短路即插上跳线帽
A0 | A1 | A2 | ADDR |
短路 | 短路 | 短路 | 0X20 |
悬空 | 短路 | 短路 | 0x21 |
短路 | 悬空 | 短路 | 0x22 |
悬空 | 悬空 | 短路 | 0x23 |
短路 | 短路 | 悬空 | 0x24 |
悬空 | 短路 | 悬空 | 0x25 |
短路 | 悬空 | 悬空 | 0x26 |
悬空 | 悬空 | 悬空 | 0x27 |
lcd.init(); // 初始化显示屏
lcd.clear();//清空显示屏
lcd.print(); //显示内容
lcd.backlight(); //背光
setCursor(x,y); //设置起始坐标
参考代码
//DFRobot.com //Compatible with the Arduino IDE 1.0 //Library version:1.1 #include#include #if defined(ARDUINO) && ARDUINO >= 100 #define printByte(args) write(args); #else #define printByte(args) print(args,BYTE); #endif uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4}; uint8_t note[8] = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0}; uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0}; uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0}; uint8_t duck[8] = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0}; uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0}; uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0}; uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4}; LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x20 for a 20 chars and 4 line display(All jumpers should be connected!) void setup() { // Serial.begin(57600); lcd.init(); // initialize the lcd lcd.backlight(); lcd.createChar(0, bell); lcd.createChar(1, note); lcd.createChar(2, clock); lcd.createChar(3, heart); lcd.createChar(4, duck); lcd.createChar(5, check); lcd.createChar(6, cross); lcd.createChar(7, retarrow); lcd.home(); lcd.setCursor(0, 0); for(int i = 0;i < 20; i++) lcd.printByte(6); lcd.setCursor(0, 1); lcd.printByte(6); lcd.print(" Hello world "); lcd.printByte(6); lcd.setCursor(0, 2); lcd.printByte(6); lcd.print(" i "); lcd.printByte(3); lcd.print(" arduinos! "); lcd.printByte(6); lcd.setCursor(0, 3); for(int i = 0;i < 20; i++) lcd.printByte(6); // lcd.clear(); } void loop() { }