Created
October 23, 2018 07:43
-
-
Save AungWinnHtut/c7b62647da96498a6dc7a8d53e07aaab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Displays text sent over the serial port (e.g. from the Serial Monitor) on | |
* an attached LCD. | |
*/ | |
//This program is originally an example program for LiquidCrystal_I2C.h | |
//This program is modified by Dr. Aung Win Htut | |
//This program read from serial and print on lcd | |
//we modified it to move next line if char reach col 16 | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
LiquidCrystal_I2C lcd(0x3F, 16, 2); //I2C address is 0x3F but sometime it will be 0x27 | |
//location controlled variables | |
int row=0; | |
int col=0; | |
int count =0; //character counter | |
//Setup lcd and serial here | |
void setup() | |
{ | |
lcd.begin(); | |
lcd.backlight(); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
//if data exists | |
if (Serial.available()) { | |
delay(100); | |
lcd.clear(); | |
while (Serial.available() > 0) { | |
char ch = Serial.read(); | |
//check if data is not new line character | |
//check if the col exceeds 16 then move to next row and start from first col | |
//if not move column and print that char in lcd | |
//if we found \n or \r then the line is over | |
//we must move our cursor to 0,0 location | |
if(ch!='\n'&&ch!='\r') | |
{ | |
if(col>=16) | |
{ | |
col=0; | |
row++; | |
} | |
lcd.setCursor(col,row); | |
lcd.write(ch); | |
col++; | |
} | |
else{ //we found new line then prepare for new input | |
col=0; | |
row=0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment