Once again i've been playing around with custom characters on an LCD using the LiquidCrystal library. I've been working with redefining the custom characters on the fly to open up many more possible characters the LCD can display.
This code offers 2 different sets of custom characters. Starting the cursor as (0,0) it fills the segment one line at a time from left to right. It then wipes the stored custom characters and then adds the new ones. The next segment then fills in one line at a time from top to bottom. It goes back and forth like this to fill the entire screen with fully filled in segments.
/*
This sketch shows how to use multiple sets of custom characters
at the same time. This is achieved by redefining the character
sets on the fly. Initial code made for a 16x2 LCD using the
LiquidCrystal library. Can be adapted for other sized LCDs.
The Circuit:
LCD RS pin to D7
LCD Enable pin to D6
LCD D4 pin to D5
LCD D5 pin to D4
LCD D6 pin to D3
LCD D7 pin to D2
LCD Vee tied to a pot to control brightness
LCD Vss and R/W tied to ground
LCD Vcc to +5V
LCD pin 15 tied to pushbutton for control of back light
Made by Michael Pilcher
3/10/2010
*/
// include the library
#include <LiquidCrystal.h>
// initialize the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// define integers for the cursor location
int x=0;
int y=0;
void setup()
{
// sets the LCD's rows and columns:
lcd.begin(16, 2);
}
void customclear()
{
// ensures all custom character slots are clear before new custom
// characters can be defined.
byte blank[8] =
{
B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000
};
for(int i = 0; i < 8; i++)
{
lcd.createChar(i, blank);
}
}
// filles a segment one line at a time fron left to right.
void customset1()
{
customclear();
// arrays to form one set of custom characters
byte line1[8] =
{
B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000
};
byte line2[8] =
{
B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000
};
byte line3[8] =
{
B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100
};
byte line4[8] =
{
B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110
};
// assignes each segment a write number
lcd.createChar(0, line1);
lcd.createChar(1, line2);
lcd.createChar(2, line3);
lcd.createChar(3, line4);
}
// fills a segment one line at a time from top to bottom.
void customset2()
{
customclear();
// arrays to form one set of custom characters
byte line1[8] =
{
B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000
};
byte line2[8] =
{
B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000
};
byte line3[8] =
{
B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000
};
byte line4[8] =
{
B11111, B11111, B11111, B11111, B00000, B00000, B00000, B00000
};
byte line5[8] =
{
B11111, B11111, B11111, B11111, B11111, B00000, B00000, B00000
};
byte line6[8] =
{
B11111, B11111, B11111, B11111, B11111, B11111, B00000, B00000
};
byte line7[8] =
{
B11111, B11111, B11111, B11111, B11111, B11111, B11111, B00000
};
// assignes each segment a write number
lcd.createChar(0, line1);
lcd.createChar(1, line2);
lcd.createChar(2, line3);
lcd.createChar(3, line4);
lcd.createChar(4, line5);
lcd.createChar(5, line6);
lcd.createChar(6, line7);
}
void loop()
{
customset1();
for(int i = 0; i < 4; i++)
{
lcd.setCursor(x, y);
lcd.write(i);
delay(100);
}
lcd.setCursor(x, y);
lcd.write(255);
delay(100);
x++;
if(x > 15)
{
x = 0;
y++;
}
if(y > 1)
{
x = 0;
y = 0;
lcd.clear();
}
customset2();
for(int i = 0; i < 7; i++)
{
lcd.setCursor(x, y);
lcd.write(i);
delay(100);
}
lcd.setCursor(x, y);
lcd.write(255);
delay(100);
x++;
if(x > 15)
{
x = 0;
y++;
}
if(y > 1)
{
x = 0;
y = 0;
lcd.clear();
}
}
I hope this can be used as a guide at expanding what can be done with these LCDs.