so I have a serial LCD 2x16 from radio shack, specifically Parallax 27977. it works nicely, been playing with it, makin it swear and say silly things (even has a built in mic, but I ahve yet to play with that). anyways rather than memorize the function hex commands, i want to write up a simple library to do those for me, and I can just continue to use Serial.write to display things on it. I have the following code written so far, but nothing seems to happen when used. I removed any input arguments (baud and channel) using the KISS debugging approach. hard coded to use serial1 so I can keep my pc connected and play.
/*parallax 2x16 backlit display
serial w/ speaker
pn# 27977 $35 at rat shack
0-7 CUSTOM CHAR
10 DOWN
12 CLEAR and return to 0x0, pause 5ms
13 CARRRAIGE RETURN
17 BACKLIGHT ON
18 BACKLIGHT OFF
21 DISPLAY OFF
22 DISPLAY ON no curser no blink, pause may be needed
248-255 DEFINE CUSTOME CHARS must be followed by 8 bytes 5x8 grid
*/
#ifndef LCD27977_H
#define LCD27977_H
#include "WProgram.h"
class LCD27977{
private:
int channel;
int baud;
public:
LCD27977(); //locked on serial1
~LCD27977();
void on();
void off();
void BLOn();
void BLOff();
void clear();
};
#endif
#include "LCD27977.h"
LCD27977::LCD27977(){
channel=1;
baud=9600;
delay(100); //initizes serial on arduino, and saves channel number
switch(channel){ //up to 4 channels to accomadate Mega
case 0:
Serial.begin(baud);
break;
case 1:
Serial1.begin(baud);
break;
case 2:
Serial2.begin(baud);
break;
case 3:
Serial3.begin(baud);
break;
}
}
LCD27977::~LCD27977(){ }
void LCD27977::on(){
delay(100);
switch(channel){
case 0:
Serial.write(0x16);
break;
case 1:
Serial1.write(0x16);
break;
case 2:
Serial2.write(0x16);
break;
case 3:
Serial3.write(0x16);
break;
}
}
void LCD27977::off(){
switch(channel){
case 0:
Serial.write(0x15);
break;
case 1:
Serial1.write(0x15);
break;
case 2:
Serial2.write(0x15);
break;
case 3:
Serial3.write(0x15);
break;
}
}
void LCD27977::BLOn(){ //backlight on
switch(channel){
case 0:
Serial.write(0x11);
break;
case 1:
Serial1.write(0x11);
break;
case 2:
Serial2.write(0x11);
break;
case 3:
Serial3.write(0x11);
break;
}
}
void LCD27977::BLOff(){ //backlight off
switch(channel){
case 0:
Serial.write(0x12);
break;
case 1:
Serial1.write(0x12);
break;
case 2:
Serial2.write(0x12);
break;
case 3:
Serial3.write(0x12);
break;
}
}
void LCD27977::clear() {
switch(channel){
case 0:
Serial.write(0x0c);
break;
case 1:
Serial1.write(0x0c);
break;
case 2:
Serial2.write(0x0c);
break;
case 3:
Serial3.write(0x0c);
break;
}
delay(5);
}
my code compiles fine, but once uploaded does nothing. the following is simple sketch that works exactly the way you think it would
void setup(){
Serial1.begin(9600);
}
void loop(){
// delay(100); //in mfr example BASIC code?
Serial1.write(0x16); //turns on deisplay
Serial1.write("stupid world");
Serial1.write(0x11); //turns on backlight
delay(4500);
Serial1.write(0x0c); //clears screen and CR
delay(10); //needed after 0C command
Serial1.write(0x12); //turns backlight off
delay(1500);
}
this is my second class, and the last one was in processing and rediulosy simple