Guest

uvok / LCD

By: a guest on Sep 4th, 2010  |  syntax: C  |  size: 1.58 KB  |  hits: 191  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. // include the library code:
  2. #include <LiquidCrystal.h>
  3.  
  4. // initialize the library with the numbers of the interface pins
  5. LiquidCrystal lcd(2, 3, 8, 9, 10, 11);
  6. int count=0;
  7.  
  8. void setup(){
  9.   // set up the LCD's number of rows and columns:
  10.   lcd.begin(16, 2);
  11.   // initialize the serial communications:
  12.   Serial.begin(9600);
  13.   lcd.print("Send serial data");
  14. }
  15.  
  16. // Scrolling *very* long messages results in error (line jumping etc).
  17. // This function *should* prevent it
  18. void overflow() {
  19.   // Autoscroll schonmal aus, brauchen wir dann bis zum "neuen" 32. Chr eh nicht mehr
  20.   lcd.noAutoscroll();
  21.  
  22.   // lass den Nutzer noch zu Ende lesen
  23.   delay(1500);
  24.  
  25.   // Loeschen und zur ersten Position
  26.   lcd.clear();
  27.  
  28.   // Counter wieder auf 0
  29.   count=0;
  30. }
  31.  
  32. void loop()
  33. {
  34.   // when characters arrive over the serial port...
  35.   if (Serial.available()) {
  36.     // wait a bit for the entire message to arrive
  37.     delay(100);
  38.     // clear the screen
  39.     lcd.clear();
  40.     // read all the available characters
  41.     while (Serial.available() > 0) {
  42.       // display each character to the LCD
  43.       count++;
  44.       lcd.write(Serial.read());
  45.      
  46.       // wechsele in die naechste Zeile
  47.       if(count==16) lcd.setCursor(0,1);
  48.      
  49.       // Autoscroll an und warten bis der Nutzer die Displayanzeige gelesen hat
  50.       if(count==32) { lcd.autoscroll(); delay(2000); }
  51.      
  52.       //Und los geht das scrollen
  53.       if(count>=32) delay(500);
  54.      
  55.       // Bevor der Pufferueberluf (?) beginnt
  56.       if(count==54) overflow();
  57.     }
  58.     lcd.noAutoscroll();
  59.   }
  60.   count = 0;
  61. }