Header Ads

ArduinoでLCDディスプレイをI2Cで使う

LCDディスプレイをArduinoで使います。通信はI2Cの4ピンタイプなので、5V→5V、GND→GND、SDA→A4、SCL→A5に繋ぎます。ライブラリはこれ。I2Cのアドレスがわからない場合には、I2CScannerを使う。これは、Scannerで39なので進数変換器で16進数に変換すると、27になるので0x27をアドレスに使う。
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("2018/3/19");
lcd.setCursor(0, 1);
lcd.print("Arduino!");
delay(3000);
lcd.clear();
delay(3000);
lcd.noBacklight();
}
void loop()
{
}
view raw gistfile1.txt hosted with ❤ by GitHub
Powered by Blogger.