Skip to content

Instantly share code, notes, and snippets.

@machinaut
Created March 24, 2010 23:22
Show Gist options
  • Save machinaut/342947 to your computer and use it in GitHub Desktop.
Save machinaut/342947 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
/*
void setup() {
Serial.begin(9600);
// Initialize
clearLCD();
backlightOn();
}
char text[ ] = "I like Linux, Open-Source, and Programming! :-)";
void loop() {
int i;
// Initialize
clearLCD();
backlightOn();
//Print text on each line
selectLineOne();
Serial.print("ajray, Comp Engr");
for (i=0 ; i < 20 ; i++) {
selectLineTwo();
Serial.print(text + i);
delay(1000);
}
} // loop again
//SerialLCD Functions
void selectLineOne(){ //puts the cursor at line 0 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(128, BYTE); //position
}
void selectLineTwo(){ //puts the cursor at line 2 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(192, BYTE); //position
}
void goTo(int position) { //position = line 1: 0-19, line 2: 20-39, etc, 79+ defaults back to 0
if (position<20){ Serial.print(0xFE, BYTE); //command flag
Serial.print((position+128), BYTE); //position
}else if (position<40){Serial.print(0xFE, BYTE); //command flag
Serial.print((position+128+64-20), BYTE); //position
}else if (position<60){Serial.print(0xFE, BYTE); //command flag
Serial.print((position+128+20-40), BYTE); //position
}else if (position<80){Serial.print(0xFE, BYTE); //command flag
Serial.print((position+128+84-60), BYTE); //position
} else { goTo(0); }
}
void clearLCD(){
Serial.print(0xFE, BYTE); //command flag
Serial.print(0x01, BYTE); //clear command.
}
void backlightOn(){ //turns on the backlight
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(157, BYTE); //light level.
}
void backlightOff(){ //turns off the backlight
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(128, BYTE); //light level for off.
}
void backlight50(){ //sets the backlight at 50% brightness
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(143, BYTE); //light level for off.
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
Serial.print(0xFE, BYTE);
}
*/
void setup()
{
Serial.begin(9600);
backlightOn();
}
void loop()
{
selectLineOne();
delay(100);
Serial.print("Alex Ray, CPE/TE");
selectLineTwo();delay(300);Serial.print("I like Linux, Op");
selectLineTwo();delay(300);Serial.print(" like Linux, Ope");
selectLineTwo();delay(300);Serial.print("like Linux, Open");
selectLineTwo();delay(300);Serial.print("ike Linux, OpenS");
selectLineTwo();delay(300);Serial.print("ke Linux, OpenSo");
selectLineTwo();delay(300);Serial.print("e Linux, OpenSou");
selectLineTwo();delay(300);Serial.print(" Linux, OpenSour");
selectLineTwo();delay(300);Serial.print("Linux, OpenSourc");
selectLineTwo();delay(300);Serial.print("inux, OpenSource");
selectLineTwo();delay(300);Serial.print("nux, OpenSource ");
selectLineTwo();delay(300);Serial.print("ux, OpenSource a");
selectLineTwo();delay(300);Serial.print("x, OpenSource an");
selectLineTwo();delay(300);Serial.print(", OpenSource and");
selectLineTwo();delay(300);Serial.print(" OpenSource and ");
selectLineTwo();delay(300);Serial.print("OpenSource and P");
selectLineTwo();delay(300);Serial.print("penSource and Pr");
selectLineTwo();delay(300);Serial.print("enSource and Pro");
selectLineTwo();delay(300);Serial.print("nSource and Prog");
selectLineTwo();delay(300);Serial.print("Source and Progr");
selectLineTwo();delay(300);Serial.print("ource and Progra");
selectLineTwo();delay(300);Serial.print("urce and Program");
selectLineTwo();delay(300);Serial.print("rce and Programm");
selectLineTwo();delay(300);Serial.print("ce and Programmi");
selectLineTwo();delay(300);Serial.print("e and Programmin");
selectLineTwo();delay(300);Serial.print(" and Programming");
selectLineTwo();delay(300);Serial.print("and Programming!");
selectLineTwo();delay(300);Serial.print("nd Programming! ");
selectLineTwo();delay(300);Serial.print("d Programming! :");
selectLineTwo();delay(300);Serial.print(" Programming! :-");
selectLineTwo();delay(300);Serial.print("Programming! :-)");
delay(1300);
}
void selectLineOne(){ //puts the cursor at line 0 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(128, BYTE); //position
}
void selectLineTwo(){ //puts the cursor at line 0 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(192, BYTE); //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.print(0xFE, BYTE); //command flag
Serial.print((position+128), BYTE); //position
}else if (position<32){Serial.print(0xFE, BYTE); //command flag
Serial.print((position+48+128), BYTE); //position
} else { goTo(0); }
}
void clearLCD(){
Serial.print(0xFE, BYTE); //command flag
Serial.print(0x01, BYTE); //clear command.
}
void backlightOn(){ //turns on the backlight
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(157, BYTE); //light level.
}
void backlightOff(){ //turns off the backlight
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(128, BYTE); //light level for off.
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
Serial.print(0xFE, BYTE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment