Il est possible de redéfinir les caractères 0 à 7. pour réaliser cela, chaque caractère est défini par une matrice de 5 colonnes par 8 lignes.
Exemple pour définir un smiley :
byte smiley[8] = { B00000, B10001, B00000, B00000, B10001, B01110, B00000, };
Le code pour afficher le caractère est
#include <Wire.h> //-- Proviens de Arduino IDE
#include <LiquidCrystal_I2C.h> //-- A importer !
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
void setup() {
lcd.createChar(0, smiley);
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
lcd.backlight(); // backlight on
lcd.setCursor(0,0); //Start at character 4 on line 0
lcd.print("*** LCD I2C ****");
lcd.setCursor(0,1);
lcd.write(byte(0));
}
void loop() {}
Plus d’info : http://www.pyroelectro.com/tutorials/16x2_lcd_custom_character/theory.html
Outil très sympa fonctionnant sous windows pour défnir les caractères : http://forum.arduino.cc/index.php?PHPSESSID=7bijmc3p9tac9lmmiip8irl3k7&topic=258546.0
Exemple de réalisation :
//-- Test pour matérialiser une gauge de volume --//
// Avec Ecran LCD 1602 (16c x 2 lignes)
///////////////////////////////////////////////////
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//******** Init Librairies *********************************
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
//ECRAN->ARDUINO : GND->GND ; VCC->+5v ; SDA->A4 (UNO & NANO) 20(MEGA) ; SCL->A5 (UNO & NANO) 21 (MEGA)
//** Définition des caractères **/
byte empty_vol[8] = {
0b11111,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b11111
};
byte full_vol[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
int i;
void setup() {
lcd.begin(16, 2); // initialize the lcd
lcd.createChar(0, empty_vol);
lcd.createChar(1, full_vol);
lcd.home (); // go home
lcd.print("*** LCD I2C ****");
//** Affiche gauge vide
for (i = 0; i < 16 ; i++)
{ lcd.setCursor(i, 1);
lcd.print (char(2));
}
}
void loop()
{
//** Remplissage
for (i = 0; i < 16 ; i++)
{ lcd.setCursor(i, 1);
lcd.print (char(1));
delay (1000);
}
//** Vidage
for (i = 15; i >= 0 ; i--)
{ lcd.setCursor(i, 1);
lcd.print (char(0));
delay (1000);
}
}
Votre commentaire