I have been running the exact same code for the past two hours some times it will function other times the display shows nothing or gets stuck. I've attempted debugging it a thousand times however to no avail and every time i end up at the same code which works half the time.
The sketch is suppose to get a string from the serial monitor and then print it to the lcd screen.
The code is below.
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Using version 1.2.1
// The LCD constructor - address shown is 0x27 - may or may not be correct for yours
// Also based on YWRobot LCM1602 IIC V1
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
String input;
bool flag= false;
//int pin = 11;
void setup()
{
lcd.begin(16,2); // sixteen characters across - 2 lines
lcd.backlight();
Serial.begin(9600);
}
void loop()
{
while(Serial.available()){
input=Serial.readString();
Serial.print("\nYou input:");
Serial.println(input);
flag=false;
break;
}
if(flag==false){
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(input);
flag=true;
}
if(input=="done")
{
lcd.clear();
}
}