
uvok / LCD
By: a guest on Sep 4th, 2010 | syntax:
C | size: 1.58 KB | hits: 191 | expires: Never
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 8, 9, 10, 11);
int count=0;
void setup(){
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
lcd.print("Send serial data");
}
// Scrolling *very* long messages results in error (line jumping etc).
// This function *should* prevent it
void overflow() {
// Autoscroll schonmal aus, brauchen wir dann bis zum "neuen" 32. Chr eh nicht mehr
lcd.noAutoscroll();
// lass den Nutzer noch zu Ende lesen
delay(1500);
// Loeschen und zur ersten Position
lcd.clear();
// Counter wieder auf 0
count=0;
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
count++;
lcd.write(Serial.read());
// wechsele in die naechste Zeile
if(count==16) lcd.setCursor(0,1);
// Autoscroll an und warten bis der Nutzer die Displayanzeige gelesen hat
if(count==32) { lcd.autoscroll(); delay(2000); }
//Und los geht das scrollen
if(count>=32) delay(500);
// Bevor der Pufferueberluf (?) beginnt
if(count==54) overflow();
}
lcd.noAutoscroll();
}
count = 0;
}