arduino‎ > ‎arduino cursus‎ > ‎

99. snippets

 
 


 

2 lijnen op LCD display

/*
 * Displays text sent over the serial port (e.g. from the Serial Monitor) on
 * an attached LCD.
 * DFRobot.com
 *Compatible with the Arduino IDE 1.0
 *Library version:1.1
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
char inData[32]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character


void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  Serial.begin(9600);
}

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) // Don't read unless
                                   // there you know there is data
    {

        if(index < 31) // One less than the size of the array
        {
            inChar = Serial.read(); // Read a character
            inData[index] = inChar; // Store it
            index++; // Increment where to write next
            inData[index] = '\0'; // Null terminate the string
        }
    }
 
 String Resultaat = inData;
 lcd.print(Resultaat.substring(0,15));
 lcd.setCursor(0,1);
 lcd.print(Resultaat.substring(16,31));
 index = 0;
        inChar=-1;
  }

}

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Comments