Parallax Serial LCD
2 rows x 16 characters Non-backlit (#27976)
2 rows x 16 characters Backlit (#27977)
4 rows x 20 characters Backlit (#27979)
http://elmicro.com/files/parallax/seriallcd-v20.pdf
The best way to interface to this Serial LCD is to use the software serial library offered by Arduino environment. Be sure that the following is on your code.
///////////////////////// Libraries ///////////////////////////////
#include <SoftwareSerial.h>
//////////////////////// LCD Variables ///////////////////////////
SoftwareSerial mySerial(10, 11); // RX, TX
Then, write subroutines to initialize the LCD.
void initializeLCD(){
mySerial.begin(19200); //change per LCD
delay(500);
// put your setup code here, to run once:
mySerial.write(12);
delay(5);
}
Subroutines to control the screen
void LCD_clearScreen(){
mySerial.write(12);
delay(10);
}
void Turn_backlight_on_LCD(){
mySerial.write(17);
delay(5);
}
void Turn_backlight_off_LCD(){
mySerial.write(18);
delay(5);
}
void Line_Feed_LCD(){
mySerial.write(12);
delay(5);
}
void Carriage_Return_LCD(){
mySerial.write(13);
delay(5);
}
void Move_Cursor(int line, int pos){
switch (line){
case 0:
mySerial.write(128 + pos);
delay(5);
break;
case 1:
mySerial.write(148 + pos);
delay(5);
break;
case 2:
mySerial.write(168 + pos);
delay(5);
break;
case 3:
mySerial.write(188 + pos);
delay(5);
break;
default:
// do nothing
break;
}
delay(5);
}
To write the a float value onto the LCD, it would work best if it was converted to a string as described below using dtostrf function
void LCD_floatValue(){
int StringLen = 7;
int numVarAfterDec = 3;
static char outstr[15]; // the array to store the results
static float f_val = Lever_Position;
dtostrf(Lever_Position,7, 1, outstr);
Move_Cursor(0,0);
delay(5);
mySerial.print("Value ");
mySerial.println (outstr);
}
No comments:
Post a Comment