Skip to content

Instantly share code, notes, and snippets.

@zinntikumugai
Created February 22, 2017 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zinntikumugai/4a39f071ddd82736ebbf47a6d6b8637b to your computer and use it in GitHub Desktop.
Save zinntikumugai/4a39f071ddd82736ebbf47a6d6b8637b to your computer and use it in GitHub Desktop.
#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