Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- October 11, 2019
- This is a demonstration of how to make custom characters for a 16x2 LCD on an Arduino (Uno).
- */
- #include <LiquidCrystal.h>
- int Vpin = 0;
- float voltaje;
- float V;
- LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // pines RS, E, D4, D5, D6, D7 de modulo 1602A
- //custom character https://lastminuteengineers.com/arduino-1602-character-lcd-tutorial/
- /*
- byte DIV_0_OF_5[8] = {
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000
- }; // 0 / 5
- byte DIV_1_OF_5[8] = {
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000
- }; // 1 / 5
- byte DIV_2_OF_5[8] = {
- B11000,
- B11000,
- B11000,
- B11000,
- B11000,
- B11000,
- B11000,
- B11000
- }; // 2 / 5
- byte DIV_3_OF_5[8] = {
- B11100,
- B11100,
- B11100,
- B11100,
- B11100,
- B11100,
- B11100,
- B11100
- }; // 3 / 5
- byte DIV_4_OF_5[8] = {
- B11110,
- B11110,
- B11110,
- B11110,
- B11110,
- B11110,
- B11110,
- B11110
- }; // 4 / 5
- byte DIV_5_OF_5[8] = {
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111,
- B11111
- }; // 5 / 5
- */
- // The Arduino pages say to prefix a byte value declaration with capital B,
- // but many other places use 0b (zero & b) instead?
- // The capital B seems to be an Arduino-specific instruction.
- // The sketches I have used (that worked) always used 0b ...
- byte DIV_0_OF_5[8] = {
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000
- }; // 0 / 5
- byte DIV_1_OF_5[8] = {
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000
- }; // 1 / 5
- byte DIV_2_OF_5[8] = {
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000
- }; // 2 / 5
- byte DIV_3_OF_5[8] = {
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100
- }; // 3 / 5
- byte DIV_4_OF_5[8] = {
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110
- }; // 4 / 5
- byte DIV_5_OF_5[8] = {
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111
- }; // 5 / 5
- /**
- Fonction de configuration de l'écran LCD pour la barre de progression.
- Utilise les caractéres personnalisés de 0 à 5 (6 et 7 restent disponibles).
- */
- // You can use the function below, but it must be called in setup() after the lcd.begin() call.
- void setup_progressbar() {
- /* Enregistre les caractères personnalisés dans la mémoire de l'écran LCD */
- lcd.createChar(0, DIV_0_OF_5);
- lcd.createChar(1, DIV_1_OF_5);
- lcd.createChar(2, DIV_2_OF_5);
- lcd.createChar(3, DIV_3_OF_5);
- lcd.createChar(4, DIV_4_OF_5);
- lcd.createChar(5, DIV_5_OF_5);
- }
- void setup() {
- lcd.begin(16, 2); // inicializa a display de 16 columnas y 2 lineas
- lcd.clear(); // to clear any possible random chars from starting up
- setup_progressbar();
- }
- void loop() {
- lcd.setCursor(0, 0);
- lcd.write(byte(0)); // This line is how to write one of the custom characters.
- lcd.write(byte(1));
- lcd.write(byte(2));
- lcd.write(byte(3));
- lcd.write(byte(4));
- lcd.write(byte(5));
- lcd.setCursor(0, 1);
- lcd.write(byte(5));
- lcd.write(byte(4));
- lcd.write(byte(3));
- lcd.write(byte(2));
- lcd.write(byte(1));
- lcd.write(byte(0));
- delay(3000);
- lcd.clear();
- delay(1000);
- // Below is commented out just for testing the custom chars.
- /*
- voltaje = analogRead (Vpin);
- V = voltaje / 1024 * 5.0;
- lcd.print("SondaV= ");
- lcd.print(V);
- delay(500);
- lcd.clear();
- */
- }
- // ~~~~~~~~ the end ~~~~~~~~~
Add Comment
Please, Sign In to add comment