Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

OpenAccess LCD functions

OpenAccess LCD functions

Here is the set of variables related to the LCD, the backlight and contrast values are important.  ‘printname’ is not here for the LCD, it actually is used when returning strings over the serial port.  ‘transmit’ is what I use to send commands to the LCD.

//LCD stuff

int back_val = 255;
int cont_val = 90;
String transmit = “”;
String printname = “”;

This is my initializer for the LCD (the LCD is on Serial3), it sets the contrast and backlight value to the values in memory (could use the command bytes) so that whatever state the LCD is in, it gets set up right.

void LCD_init()
{
Serial3.begin(115200);
LCD_clear();

transmit = “CONTRAST;”;
transmit += cont_val;
Serial3.println(transmit);

transmit = “BACKLIGHT;”;
transmit += back_val;
Serial3.println(transmit);
}

These are the commands to display things on the LCD manually (like using the Serial print and println commands).  These are used internal to the code all the time, there are wrappers though that let them get used by the serial port commands.

void LCD_displn(String prints,int line)//displays on a given line, does not emulate CR LF
{
transmit = “DISPLN;”;
transmit += line;
transmit += “;”;
transmit += prints;
Serial3.println(transmit);
}
void LCD_disp(String prints)
{
transmit = “DISP;”;
transmit += prints;
Serial3.println(transmit);
}

These set the backlight and contrast from the serial console on the OpenAccess

// sets contrast
//format: CONTRAST;<analog value, 0-255 or nothing for default>
void SCmd_contrast()
{

transmit = “CONTRAST;”;
char *arg;
//Serial.println(“contrast”);
arg = SCmd.next();
if (arg != NULL)
{
transmit += arg;
}
else
{
transmit += cont_val;
}
Serial3.println(transmit);
}
// sets backlight
//format: BACKLIGHT;<analog value, 0-255 or nothing for default>
void SCmd_backlight()
{

transmit = “BACKLIGHT;”;
char *arg;
//Serial.println(“backlight”);
arg = SCmd.next();
if (arg != NULL)
{
transmit += arg;
}
else
{
transmit += back_val;
}
Serial3.println(transmit);
}

This is my clear command (it is a 2 line LCD)  This is modular so you can fill in your own code to clear whatever display you use:

inline void LCD_clear()
{
LCD_displn(” “,0);
LCD_displn(” “,1);
}

This is how you can manually overwrite the display from the console:

// uses display
//format: DISP;<0=line 1, 1=line 2 (or no argument to clear the display)>;<string (or no argument to clear the line)>
void SCmd_display()
{
char *arg;
arg = SCmd.next();
if (arg != NULL)
{
if (atoi(arg) == 0)
{
arg = SCmd.next();
if (arg != NULL)
{
LCD_displn(arg,0);
}
else
{
LCD_displn(” “,0);
}
}
else if (atoi(arg) == 1)
{
arg = SCmd.next();
if (arg != NULL)
{
LCD_displn(arg,1);
}
else
{
LCD_displn(” “,1);
}
}
}
else
{
LCD_clear();
}
}

 

This runs every loop that nothing interesting is happening and chooses the splash screen:

void LCD_default()
{
LCD_clear();
if(doorbell)
{
LCD_displn(“Welcome: press “,0);
LCD_displn(“”#” to enter “,1);
}
else if(doorhold)
{
LCD_displn(“Door held: press”,0);
LCD_displn(“”#” to enter “,1);
}
else
{
LCD_displn(“i3 Detroit “,0);
LCD_displn(“Hackerspace “,1);
}
}

That’s my LCD functions, you can see that I compartmentalized it a lot so it is easy to change the protocol or library of your display. This is part of the greater OpenAccess project.

Read more Here

Pinned onto

Related Pins

Arduino Stopwatch
Arduino Stopwatch
App note: General overview of IR transmission in free ambient
App note: General overview of IR transmission in free ambient
Sonicare toothbrush teardown: microcontroller, H bridge, and inductive charging
Sonicare toothbrush teardown: microcontroller, H bridge, and inductive charging
App note: Using Vishay infrared receivers in a Wi-Fi environment
App note: Using Vishay infrared receivers in a Wi-Fi environment
Skill Sunday: Uploading to your Arduino via a Network
Skill Sunday: Uploading to your Arduino via a Network
One Phase Power Meter
One Phase Power Meter
WiFi Toilet Vacancy Sensor
WiFi Toilet Vacancy Sensor
HAL 9000 reimagined as a useless machine
HAL 9000 reimagined as a useless machine
Using the XMEGA Clock System
Using the XMEGA Clock System
An Arduino VU meter for classrooms
An Arduino VU meter for classrooms
DIY Calculator
DIY Calculator
Build your own robotic vacuum from scratch
Build your own robotic vacuum from scratch
An animatronic talking takeout container
An animatronic talking takeout container
Restoring a Xerox Alto day 7: experiments with disk and Ethernet emulators
Restoring a Xerox Alto day 7: experiments with disk and Ethernet emulators
IDE 1.6.12 released with Sierra support and more
IDE 1.6.12 released with Sierra support and more
IoT Propane Tank
IoT Propane Tank
Industry Standard Single-Ended Current Mode PWM Controller
Industry Standard Single-Ended Current Mode PWM Controller
Wifi enabled 8×64 pixel LED matrix display
Wifi enabled 8×64 pixel LED matrix display
Arduino Disco Lights
Arduino Disco Lights
PIXIE is an Arduino-based NeoPixel watch
PIXIE is an Arduino-based NeoPixel watch

Top


Shares