SerialDisplay.pde 811 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Displays text sent over the serial port (e.g. from the Serial Monitor) on
  3. * an attached LCD.
  4. * YWROBOT
  5. *Compatible with the Arduino IDE 1.0
  6. *Library version:1.1
  7. */
  8. #include <Wire.h>
  9. #include <LiquidCrystal_I2C.h>
  10. LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
  11. void setup()
  12. {
  13. lcd.init(); // initialize the lcd
  14. lcd.backlight();
  15. Serial.begin(9600);
  16. }
  17. void loop()
  18. {
  19. // when characters arrive over the serial port...
  20. if (Serial.available()) {
  21. // wait a bit for the entire message to arrive
  22. delay(100);
  23. // clear the screen
  24. lcd.clear();
  25. // read all the available characters
  26. while (Serial.available() > 0) {
  27. // display each character to the LCD
  28. lcd.write(Serial.read());
  29. }
  30. }
  31. }