Created
June 17, 2013 05:06
-
-
Save ravenlp/5794749 to your computer and use it in GitHub Desktop.
Simple Arduino code used to show data on the lcd shield over a serial connection. Ideal to have the output of a script (Node/Ruby/Pyhon etc) shown on a pretty lcd screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LiquidCrystal Library - Serial Input | |
*/ | |
/* | |
This example code is in the public domain. | |
http://arduino.cc/en/Tutorial/LiquidCrystalSerial | |
*/ | |
// include the library code: | |
#include <LiquidCrystal.h> | |
char c[33]; | |
// initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | |
void setup(){ | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// initialize the serial communications: | |
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 | |
int i = 0; | |
while (Serial.available() > 0) { | |
c[i++] = Serial.read(); | |
//lcd.write(); | |
//data += Serial.read(); | |
} | |
// Clear the rest | |
for(; i < 33; i++){ | |
c[i] = ' '; | |
} | |
//Print the first row | |
for( i = 0; i < 16; i++){ | |
lcd.write(c[i]); | |
} | |
//Print the second row | |
lcd.setCursor(0,1); | |
for( i = 16; i < 33; i++){ | |
lcd.write(byte(c[i])); | |
} | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment