Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 588675eb53cc17df8885d873674d728286739c39 @cannikin committed Dec 25, 2009
Showing with 128 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +21 −0 README.rdoc
  3. +106 −0 show_text.pde
@@ -0,0 +1 @@
+applet
@@ -0,0 +1,21 @@
+Here's a simple sketch for writing text to a SparkFun SerLCD:
+
+http://www.sparkfun.com/commerce/product_info.php?products_id=9395
+
+Since you're using the default serial output pin that Arduino also uses
+when it's being programmed, a bunch of random characters will be sent to
+the SerLCD, including possibly a control character and then a meaningful
+character that will change a setting in the display. Therefore it's usually
+best to unhook the LCD, upload your sketch and then plug it back in. The
+text may get picked up in the middle of the display, but after a couple of
+seconds you'll be in business.
+
+This sketch will write two lines to the display, one character at a time
+and then blank the screen and start over.
+
+There are several helper methods for you to use, take a look at the code
+for a description of what each does and how to use it.
+
+== Thanks
+
+This sketch uses code from http://www.arduino.cc/playground/Learning/SparkFunSerLCD
@@ -0,0 +1,106 @@
+
+// Set this to whatever text you want to print
+char line1[] = " Hello, world!";
+char line2[] = " from Arduino";
+
+#define line1Length (sizeof(line1)-1)
+#define line2Length (sizeof(line2)-1)
+
+void setup() {
+ Serial.begin(9600);
+ backlightOn();
+ clearLCD();
+}
+
+void loop() {
+ // write line 1
+ for(int i=0;i<line1Length;i++) {
+ goTo(i);
+ if (line1[i] != ' ') {
+ Serial.print(line1[i]);
+ }
+ delay(50);
+ }
+
+ // write line 2
+ for(int i=0;i<line2Length;i++) {
+ goTo(i+16);
+ if (line2[i] != ' ') {
+ Serial.print(line2[i]);
+ }
+ delay(50);
+ }
+
+ delay(2000);
+ clearLCD();
+ delay(1000);
+}
+
+// Scrolls the display left by the number of characters passed in, and waits a given
+// number of milliseconds between each step
+void scrollLeft(int num, int wait) {
+ for(int i=0;i<num;i++) {
+ serCommand();
+ Serial.print(0x18, BYTE);
+ delay(wait);
+ }
+}
+
+// Scrolls the display right by the number of characters passed in, and waits a given
+// number of milliseconds between each step
+void scrollRight(int num, int wait) {
+ for(int i=0;i<num;i++) {
+ serCommand();
+ Serial.print(0x1C, BYTE);
+ delay(wait);
+ }
+}
+
+// Starts the cursor at the beginning of the first line (convienence method for goTo(0))
+void selectLineOne() { //puts the cursor at line 0 char 0.
+ serCommand(); //command flag
+ Serial.print(128, BYTE); //position
+}
+
+// Starts the cursor at the beginning of the second line (convienence method for goTo(16))
+void selectLineTwo() { //puts the cursor at line 0 char 0.
+ serCommand(); //command flag
+ Serial.print(192, BYTE); //position
+}
+
+// Sets the cursor to the given position
+// line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
+void goTo(int position) {
+ if (position < 16) {
+ serCommand(); //command flag
+ Serial.print((position+128), BYTE);
+ } else if (position < 32) {
+ serCommand(); //command flag
+ Serial.print((position+48+128), BYTE);
+ } else {
+ goTo(0);
+ }
+}
+
+// Resets the display, undoing any scroll and removing all text
+void clearLCD() {
+ serCommand();
+ Serial.print(0x01, BYTE);
+}
+
+// Turns the backlight on
+void backlightOn() {
+ serCommand();
@jkdelauney

jkdelauney Jan 19, 2010

The serCommand() call won't work here as the backlight control code requires 0x7C instead of 0xFE.

+ Serial.print(157, BYTE);
+}
+
+// Turns the backlight off
+void backlightOff() {
+ serCommand();
+ Serial.print(128, BYTE);
+}
+
+// Initiates a function command to the display
+void serCommand() {
+ Serial.print(0xFE, BYTE);
+}

0 comments on commit 588675e

Please sign in to comment.