Skip to content

Instantly share code, notes, and snippets.

@Nickforall
Created October 25, 2016 18:20
Show Gist options
  • Save Nickforall/41def563863c9312f28416184a3679e8 to your computer and use it in GitHub Desktop.
Save Nickforall/41def563863c9312f28416184a3679e8 to your computer and use it in GitHub Desktop.
#include <LiquidCrystal.h>
LiquidCrystal lcd(10, 11, 2, 3, 4, 5);
String inputString = "";
boolean stringComplete = false;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
inputString.reserve(128); //allocate 128 bytes RAM geheugen voor de string
}
void loop() {
handleStringComplete();
}
void handleStringComplete() {
if (stringComplete) {
if(inputString.startsWith("L1:")) {
lcdLineTop(inputString.substring(3));
} else if(inputString.startsWith("L2:")) {
lcdLineBot(inputString.substring(3));
}
stringComplete = false;
inputString = "";
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar == '\n') {
stringComplete = true;
} else {
inputString += inChar;
}
}
}
void lcdLineTop(String string) {
//doe hierzo de bovenste line van de lcd handlen
Serial.println("LCD Top lijn: " + string);
lcd.setCursor(0, 0);
lcd.print(string);
}
void lcdLineBot(String string) {
//doe hierzo de bovenste line van de lcd handlen
Serial.println("LCD Bottom lijn: " + string);
lcd.setCursor(0, 1);
lcd.print(string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment