If you rotate the image you will see 48 on top and 47 below. I want to post the code but I'm unsure what to do. I know I need to surround the code so it is formatted properly for the site. Any pointers for that?
To post code properly you need to put it in code tags. The easiest way to do that is to use Edit/Copy for Forum in the IDE and paste what is copied here in a new post. The code tags will have been added for you
If you want to turn this into a library then I think the first thing to do is to reduce the code to a minimum. Perhaps just a sketch that outputs a count to a couple of locations on the vertical LCD
As it stands the sketch is too tied to the use of a VESC which obfuscates how it works
Incidentally, you could eliminate the switch/case in the vert_numbers() function by using an array of structs defining the bytes to be output for each digit
Going to clean up the code an make the font a little more elegant. I have just written out the bytes. When I get home I can work on building a proper library.
Are you aware, there are a maximum number of custom characters allowed, and the number is small-ish? Have you confirmed that you can form all the numerals with the ones you have?
When you are developing a library, it is good to create it as additional .h and .cpp files in the same directory as the test sketch. They will appear as additional tabs for the project, in the IDE. Then when you're happy with it, you can begin to move it into a library folder.
There can only be eight custom characters at a time. Also, redefining a custom character that is currently being displayed will change what is displayed.
Spent a little time on the library and came up with vNumbers
Here is the contents of the README:
vNumbers Library
================
The vNumbers library provides a way to display rotated numbers on an LCD display viewed vertically. It includes predefined conbinations of glyphs for numbers 0 to 9.
Usage
-----
1. Include the vNumbers library in your Arduino sketch by adding the following line at the beginning of your code:
#include "vNumbers.h"
2. Create an instance of the vNB class:
vNB vNumbers;
3. Call the `setup()` function to initialize the creation of the custom glyphs:
vNumbers.setup();
4. Use the `vNumbers()` function to display the larger vertical number on the LCD display:
vNumbers.vNumbers(42); // Displays the number 42
int var = 42;
vNumbers.vNumbers(var); // Will also display the number 42
float myFloat;
float randomVariable = 42.2;
myFloat = randomVariable;
vNumbers.vNumbers(int(myFloat)); // Also displays 42
The `vNumbers()` function accepts an integer as input. It can display numbers from 0 to 99. If the input is 100 then 99 will be displayed, but nothing will be displayed for numbers outside this range (this will most likely change soon).
Vertical position
-----------------
The position on the numbers is (13, 0) and (13, 1) making the top of the screen the right side in a horizontal position. I found this was the easiest placement with my current code.
Dependencies
------------
- Arduino.h: This library requires the Arduino core library for basic functionality.
- LiquidCrystal or LiquidCrystal_I2C: The vNumbers library depends on either the LiquidCrystal or LiquidCrystal_I2C library for controlling the LCD display. Make sure to include the appropriate library based on your LCD type.
License
-------
This library is unreleased.
Author
------
The vNumbers library is developed and maintained by Vatrius.
Keep in mind this is just a rough outline of what I have so far.
Have you changed the font ? I get different shapes when I try your sketch.
UKHeliBob wrote about reducing it to a minimum.
You have a switch-case to create a number out of two bytes, but that information can be put into a table.
So this is what I got. You may use it or not, do what suits you best.
// 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]);
}
@Koepel yes, I have changed the font. I will post the code when I get home.
I'm looking at the possible placements on the screen and I have 1. Screen fit
The full screen can be filled from top to bottom with up to 10 large numbers. 2. Alt 1
The position on the numbers is shifted down but only 8 large numbers can occupy the screen at one time 3. Alt 2
The position of the numbers are shifted down one more space with 8 large numbers able to occupy the screen.
I'm seeing these positions being used to allow the user to define the position of the numbers and also allow numbers greater than 99 to be displayed. When I work out the kinks I believe the positions could also be used for vertical and horizontal scrolling numbers
I would create two functions (or two options for a single function), so both can be used. Like Celsius and Fahrenheit can both be used with some libraries.
First function: A font row of 0...4, starting at the top, leaving the bottom character unused.
Second function: A LCD row position of 0...13.
For example:
// Two different functions:
verticalLCD.number(0, 0, 9);
verticalLCD.numberLCDRow(5, 0, 9);
// A single function:
verticalLCD.number(0, -1, 0, 9); // set unused variable to -1
verticalLCD.number(-1, 5, 0, 9); // set unused variable to -1