FORGE
lcd.setCursor(0, 1);
lcd.print(“world”);
}
void loop() {
for(int i=0; i<11; i++) {
lcd.scrollDisplayRight();
delay(500);
}
for(int i=0; i<11; i++) {
lcd.scrollDisplayLeft();
delay(500);
}
}
We used a slightly different mechanism for displaying
the text on two lines. We created each line separately,
and used the setCursor() method to put it in the
correct position.
Let’s now take a look at how to create custom
characters. We can use byte arrays here. 0s represent
pixels that are off and 1s represent pixels that are on.
We’ve also taken a slightly different approach to
writing out the characters (because this is slightly
simpler in Arduino). Instead of overwriting the whole
message each time, we pop the cursor in the same
place and write out a single byte with the new
character. The shortened code for Arduino is:
#include <LiquidCrystal.h>
LiquidCrystal lcd(21, 19, 17, 16, 15, 14);
byte star_1[8] = {
B00000,
B00000,
B00000,
B00100,
B00000,
B00000,
B00000,
};
...
byte star_4[8] = {
B10101,
B10001,
B01010,
B10101,
B01010,
B10001,
B10101,
};
void setup() {
lcd.begin(16, 2);
lcd.createChar(0, star_1);
lcd.createChar(1, star_2);
lcd.createChar(2, star_3);
lcd.createChar(3, star_4);
}
void loop() {
lcd.setCursor(0,0);
lcd.write(byte(0));
delay(500);
lcd.setCursor(0,0);
lcd.write(byte(1));
delay(500);
lcd.setCursor(0,0);
lcd.write(byte(2));
delay(500);
lcd.setCursor(0,0);
lcd.write(byte(3));
delay(500);
}
Hopefully, we have given you enough knowledge to
include LCDs in your builds. They are the simplest,
easiest, and cheapest way of getting extra bits of
text in your projects. They can be a simple add-on to
output useful diagnostics (especially for untethered
projects that can’t use USB serial) or critical parts of
the interface.
Make sure you have got one or two spares in
your kit box and you might find that your projects go
a little smoother.
Left
We found that we
wanted full contrast,
so just connected
the contrast pin
to ground