// Ensure Serial Monitor has "No Line Ending"
/*
The purpose of this code is to be able to both enter text into the serial command line, store it to memory, and display it on the LCD screen.
If the text exceeds 16 chars, it is rejected by the code (ver I)
"newWordFlag" ensues the word doesn't print continously. "printFlip" ensures the word only prints once
*/
#include <EEPROM.h>
#include <LiquidCrystal.h>
#define SERIAL_BUFFER_SIZE 32
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
bool newWordFlag = false;
int len;
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print("System Ready");
while (!Serial) {}
Serial.println("System Ready");
}
void loop() {
static uint8_t charCount = 0;
char line_1[SERIAL_BUFFER_SIZE];
char incomingChar;
if ((len = Serial.available()) > 0) { // Captures input from serial
Serial.print("Received ");
Serial.print(len);
Serial.println(" char");
if ((incomingChar = Serial.read()) != '\n' && charCount < SERIAL_BUFFER_SIZE) {
line_1[charCount++] = incomingChar;
}
else {
lcd.clear();
line_1[charCount] = 0;
len = charCount;
charCount = 0;
Serial.print("Received: ");
Serial.println(line_1);
EEPROM.write(24, len);
for (int i = 0; i <= len; i++) {
EEPROM.write(25 + i, line_1[i]);
newWordFlag = true;
}
}
}
if (newWordFlag) {
len = EEPROM.read(24);
for (int j = 25; j <= len + 24; j++) {
lcd.print((char)EEPROM.read(j));
Serial.print((char)EEPROM.read(j));
Serial.println();
newWordFlag = false;
}
//Serial.print("Broken"); // Used to test conditional, Enters "for"?
//Serial.println();
}
}