I got an idea to make a simple LCD that is controlled via a serial connection with a few simple commands to clear the display, display time since reset, etc.. So I made it, and I figured I would give it to the community, I have attached the circuit diagram below and I ask for no credit; take the code and do what you want with it. Enjoy!
Circuit and code file is attached below.
//Created: April 2, 2016 by Michael Pate (mike44449)
//I ask for no credit, do what you want with my code :)
//There is nothing in this circuit but a 16x2 lcd connected
//with the provided circuit.
//Include the library and the pins that its connected to.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//String to store what is put into the serial monitor.
String serialIn;
void setup() {
// put your setup code here, to run once:
//Setup a serial connection and initilize the LCD.
Serial.begin(9600);
lcd.begin(16, 2);
//Display the commands to the user with the serial monitor.
Serial.println("ENTER TEXT ABOVE");
Serial.println("clear - CLEAR TEXT");
Serial.println("millis - DISPLAY MILLIS SINCE RESET");
Serial.println("millisCon - DISPLAY MILLIS SINCE RESET UNTIL RESET");
Serial.println(" WARNING: millisCon CANNOT BE STOPPED WITHOUT A RESET.\n\n");
Serial.println("------------------------------");
//Flash a command on the LCD for 2 seconds, then clear it.
lcd.print("ENTER SERIAL");
delay(2000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
//Put the buffer contents into the string.
serialIn = Serial.readString();
//If the string entered is a command (clear), then clear
//the display and let the user know via serial.
if (serialIn == "clear"){
lcd.clear();
Serial.println("LCD: TEXT ERASED");
//delete the serial buffer.
Serial.flush();
}
//If the command was "millis", display the millis since reset.
if (serialIn == "millis"){
lcd.print(millis());
Serial.println("CURRENT: MILLIS FUNC.");
Serial.flush();
}
//If they want to see a count-up of millis, use the command "millisCon."
if (serialIn == "millisCon"){
//It requires a reset becuase it enters an infinite loop.
Serial.println("CURRENT: MILLISCON FUNC. -TO STOP, A RESET IS REQUIRED");
for(;;){
lcd.print(millis());
delay(150);
lcd.clear();
}
}
//If the string entered does not equal any known command, display it on serial and LCD.
if (serialIn != "" && serialIn != "clear" && serialIn != "millis" && serialIn != "millisCon")
{
lcd.print(serialIn);
Serial.print("CURRENT: ");
Serial.println(serialIn);
Serial.flush();
}
}
Serial_Controlled_LCD.ino (2.26 KB)
