//this code is based upon this tutorial -> https://www.youtube.com/watch?v=nSGnCT080d8
//you can send messages over the serial monitor and display them on the lcd
#include <LiquidCrystal.h> //include lcd library
#define MAX_MESSAGE_LENGTH 64 //define max message length
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); //initialize lcd
String messageString; //define output String
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
Serial.println();
}
void loop() {
if(Serial.available()){ //if there is something in the serial buffer
readinSerial(); //read out the message
lcd.clear(); //clear the lcd
lcd.print(messageString); //print the message
}
}
void readinSerial(){
static unsigned int message_pos = 0; //saves the current pos of character
while(Serial.available() > 0){ // check if there is something in the serial buffer
static char message[MAX_MESSAGE_LENGTH]; //create a char array to store the incoming message
char inByte = Serial.read(); //read in the next Byte from the serial buffer
if(inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1)){ //check for terminating character
message[message_pos] = inByte; //save the byte from the serial buffer to the char array
message_pos++; //move to next position
}else{
message[message_pos] = '\0'; //if the message is over
messageString = message; //save it to the output String
message_pos = 0; //reset the char position
}
}
}