Codice Arduino
#include <LiquidCrystal.h>
// LCD pins <--> Arduino pins
const int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
void setup()
{
lcd.begin(16, 2); // set up number of columns and rows
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Arduino"); // print message at (0, 0)
lcd.setCursor(2, 1); // move cursor to (2, 1)
lcd.print("TEST LCD"); // print message at (2, 1)
}
void loop()
{
}
Come utilizzare il carattere personalizzato sul display LCD
#include <LiquidCrystal.h>
const int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
byte customChar[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000 };
void setup() {
lcd.begin(16, 2);
lcd.createChar(0, customChar);
lcd.setCursor(2, 0);
lcd.write((byte)0); }
void loop() { }
Più caratteri personalizzati (in questo esempio tre caratteri)
#include <LiquidCrystal.h>
// LCD pins <--> Arduino pins
const int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;
LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);
byte customChar0[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000
};
byte customChar1[8] = {
0b00100,
0b01110,
0b11111,
0b00100,
0b00100,
0b00100,
0b00100,
0b00100
};
byte customChar2[8] = {
0b00100,
0b00100,
0b00100,
0b00100,
0b00100,
0b11111,
0b01110,
0b00100
};
void setup()
{
lcd.begin(16, 2); // set up number of columns and rows
// create a new custom character (index 0)
lcd.createChar(0, customChar0);
// create a new custom character (index 1)
lcd.createChar(1, customChar1);
// create a new custom character (index 2)
lcd.createChar(2, customChar2);
lcd.setCursor(2, 0); // move cursor to (2, 0)
lcd.write((byte)0); // print the custom char 0 at (2, 0)
lcd.setCursor(4, 0); // move cursor to (4, 0)
lcd.write((byte)1); // print the custom char 1 at (4, 0)
lcd.setCursor(6, 0); // move cursor to (6, 0)
lcd.write((byte)2); // print the custom char 2 at (6, 0)
}
void loop()
{
}