Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/*
* アドレス0x27
* 16x2
*/
#define CALACTER 16
#define LINE 2
#define LCDADDRESS 0x27
//I2C版で初期化
LiquidCrystal_I2C lcd(LCDADDRESS, CALACTER, LINE);
int cnt, line;
char tmp;
void setup() {
//LCD初期化
lcd.init();
//バックライト点灯
lcd.backlight();
Serial.begin(9600);
}
void loop() {
//何か入力を受けていたら
if(Serial.available() ){
delay(100);
//画面初期化
lcd.clear();
cnt = line = 0;
//入力された文字が全てread()で読み込まれるまで
while(Serial.available() > 0) {
cnt++;
//表示可能行を超えた
if(line > LINE-1) {
Serial.println("Opps....");
break;
}
//行の終わり
if(cnt > CALACTER) {
cnt = 0;
line++;
//行変更
lcd.setCursor(0, line);
Serial.println("");
}
//入力された1文字を読み込み、LCD,シリアルに送信
tmp = Serial.read();
lcd.write(tmp);
Serial.print(tmp);
}
Serial.println("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.