// 10 August 2023
// Code by: xvatriusx
// Forum: https://forum.arduino.cc/t/vertical-16x2-lcd-numbers-made-help-with-improvement/1156130
// Changes by Koepel:
// Remove everything that is not for the vertical font.
// Changed Arduino B00000 to 'C' language 0b00000.
// Everything in a table, so it is easier to add PROGMEM.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const byte glyph[6][8] =
{
{
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111
},
{
0b11111,
0b00001,
0b00001,
0b00001,
0b00001,
0b00001,
0b00001,
0b11111
},
{
0b11111,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001
},
{
0b11111,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b11111
},
{
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b10001,
0b11111
},
{
0b11111,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b11111
}
};
const byte combine[10][2] =
{
{5, 1}, // 0
{0, 0}, // 1
{2, 4}, // 2
{4, 4}, // 3
{0, 5}, // 4
{4, 2}, // 5
{3, 2}, // 6
{0, 1}, // 7
{3, 3}, // 8
{0, 3}, // 9
};
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address and dimensions
void setup()
{
Serial.begin(115200);
Wire.begin();
lcd.begin(16, 2); // Set the LCD dimensions
lcd.backlight(); // Turn on the LCD backlight
for( int i=0; i<6; i++)
{
lcd.createChar(i, glyph[i]);
}
lcd.clear();
// Demonstration of all the numbers
vert_number(0, 0, 0);
vert_number(0, 1, 1);
vert_number(1, 0, 2);
vert_number(1, 1, 3);
vert_number(2, 0, 4);
vert_number(2, 1, 5);
vert_number(3, 0, 6);
vert_number(3, 1, 7);
vert_number(4, 0, 8);
vert_number(4, 1, 9);
}
void loop()
{
delay(100);
}
// Maybe add that a number can be placed halfway the vertical row ?
// The vertical row is 0...7
// The vertical column is 0...1
void vert_number(int row, int column, int inDigit)
{
int x = 14 - (2 * row);
int y = column;
lcd.setCursor(x, y); // x, y
lcd.write(combine[inDigit][0]);
lcd.write(combine[inDigit][1]);
}