Skip to content

Commit 4ebd14b

Browse files
committed
Fixed bug in clearing the gap between numbers, Bumped version to 1.2.3
1 parent a0c1046 commit 4ebd14b

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ Every other extension e.g. *cinclude* would do, but *hpp* seems to be common sen
137137
<br/>
138138

139139
# Revision History
140+
### Version 1.2.3
141+
- Fixed bug in clearing the gap between numbers.
142+
140143
### Version 1.2.2
141144
- Improved _createChar().
142145
- Added `VERSION_LCD_BIG_NUMBERS`.

examples/BigNumbersDemo/BigNumbersDemo.ino

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ LiquidCrystal_I2C myLCD(LCD_I2C_ADDRESS, LCD_COLUMNS, LCD_ROWS); // LCD_COLUMNS
4545
void setup() {
4646
Serial.begin(115200);
4747

48-
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
48+
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
49+
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
4950
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
5051
#endif
5152
// Just to know which program is running on my Arduino

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/ArminJo/LCDBigNumbers"
88
},
9-
"version": "1.2.2",
9+
"version": "1.2.3",
1010
"exclude": "pictures",
1111
"authors": {
1212
"name": "Armin Joachimsmeyer",

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=LCDBigNumbers
2-
version=1.2.2
2+
version=1.2.3
33
author=Armin Joachimsmeyer
44
maintainer=Armin Joachimsmeyer <armin.arduino@gmail.com>
55
sentence=Arduino library to write big numbers on a 1602 or 2004 LCD.

src/LCDBigNumbers.hpp

+27-17
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#define ONE_COLUMN_HYPHEN_CHARACTER '_' // This input character is printed as a one column hyphen. Normal hyphen / minus are printed as a hyphen with the width of the number - 1.
3535
#define ONE_COLUMN_HYPHEN_STRING "_" // This input string is printed as a one column hyphen. Normal hyphen / minus are printed as a hyphen with the width of the number - 1.
3636

37-
#define VERSION_LCD_BIG_NUMBERS "1.2.2"
37+
#define VERSION_LCD_BIG_NUMBERS "1.2.3"
3838
#define VERSION_LCD_BIG_NUMBERS_MAJOR 1
3939
#define VERSION_LCD_BIG_NUMBERS_MINOR 2
40-
#define VERSION_LCD_BIG_NUMBERS_PATCH 2
40+
#define VERSION_LCD_BIG_NUMBERS_PATCH 3
4141
// The change log is at the README.md
4242

4343
/*
@@ -293,15 +293,15 @@ class LCDBigNumbers: public Print {
293293
#else
294294
LiquidCrystal_I2C *LCD;
295295
#endif
296-
uint8_t NumberWidth;
296+
uint8_t NumberWidth; // Width of the rendered number not including the optional blank gap
297297
uint8_t NumberHeight;
298298
uint8_t FontVariant;
299299
const uint8_t (*bigNumbersCustomPatterns)[8];
300300
uint8_t NumberOfCustomPatterns;
301301
const uint8_t *bigNumbersFont;
302302
bool forceGapBetweenNumbers; // The default depends on the font used
303303
uint8_t upperLeftColumnIndex; // Start of the next character
304-
uint8_t maximumColumnIndex; // Maximum of columns to be written. Used to not clear the gap after a number which ends at the last column. ( 44 bytes program space)
304+
uint8_t maximumColumns; // Auto detected maximum of columns which can be written (e.g. 16 or 20). To avoid clearing the gap after a number which ends at the last column. (44 bytes program space)
305305
uint8_t upperLeftRowIndex; // Start of the next character
306306

307307
/*
@@ -321,7 +321,7 @@ class LCDBigNumbers: public Print {
321321
* This also sets cursor to 0.0 by call to _createChar()
322322
*/
323323
void begin() {
324-
maximumColumnIndex = 0;
324+
maximumColumns = 0;
325325
// create maximum 8 custom characters
326326
for (uint_fast8_t i = 0; i < NumberOfCustomPatterns; i++) {
327327
_createChar(i, bigNumbersCustomPatterns[i]);
@@ -432,7 +432,7 @@ class LCDBigNumbers: public Print {
432432
* Draws a big digit of size aNumberWidth x aNumberHeight at cursor position
433433
* Special characters always have the width of 1!
434434
* After each number one column gap is inserted. The gap is cleared, if not at the (last + 1) column!
435-
* @param aNumber - byte 0x00 to 0x09 or ASCII number or one of ' ', '|', '-', '_', '.' and ':' special characters to display
435+
* @param aNumber - byte 0x00 to 0x09 or ASCII number or one of these special characters: ' ', '|', '-', '_', '.', ':'
436436
* @return The number of columns written (1 to 4 currently)
437437
*/
438438
size_t writeBigNumber(uint8_t aNumberOrSpecialCharacter) {
@@ -454,12 +454,15 @@ class LCDBigNumbers: public Print {
454454
// print a one column space
455455
aNumberOrSpecialCharacter = ' ';
456456
} else {
457+
/*
458+
* Here we have numbers only
459+
*/
457460
if (aNumberOrSpecialCharacter > 9) {
458-
// if not byte 0x00 to 0x09, convert number character to ASCII
459-
aNumberOrSpecialCharacter -= '0'; // convert ASCII value to number
461+
// if not byte 0x00 to 0x09, convert ASCII character to number
462+
aNumberOrSpecialCharacter -= '0';
460463
}
461464
if (aNumberOrSpecialCharacter > 9) {
462-
// If we have a non number character now, we convert it to a space with the width of the number
465+
// If we do not have a number 0 to 9 now, we convert it to a space with the width of a number
463466
aNumberOrSpecialCharacter = ' ';
464467
}
465468
tCharacterWidth = NumberWidth;
@@ -476,8 +479,10 @@ class LCDBigNumbers: public Print {
476479
Serial.println(upperLeftColumnIndex);
477480
#endif
478481
const uint8_t *tArrayPtr = bigNumbersFont + tFontArrayOffset;
482+
// Render character row by row
479483
for (uint_fast8_t tRow = 0; tRow < NumberHeight; tRow++) {
480484
LCD->setCursor(upperLeftColumnIndex, upperLeftRowIndex + tRow);
485+
// Render all columns in a row
481486
for (uint_fast8_t i = 0; i < tCharacterWidth; i++) {
482487
uint8_t tCharacterIndex;
483488
if (aNumberOrSpecialCharacter == ' ') {
@@ -486,7 +491,7 @@ class LCDBigNumbers: public Print {
486491
tCharacterIndex = pgm_read_byte(tArrayPtr);
487492
}
488493
LCD->write(tCharacterIndex);
489-
tArrayPtr++; // next number column
494+
tArrayPtr++; // Prepare for next column, we do not use i
490495
#if defined(LOCAL_DEBUG)
491496
Serial.print(F(" 0x"));
492497
Serial.print(tCharacterIndex, HEX);
@@ -499,26 +504,31 @@ class LCDBigNumbers: public Print {
499504
Serial.print('|');
500505
#endif
501506
}
502-
upperLeftColumnIndex += tCharacterWidth;
507+
upperLeftColumnIndex += tCharacterWidth; // now we are at the index for the next number or the optional blank gap
503508

504-
if (maximumColumnIndex < upperLeftColumnIndex) {
509+
/*
510+
* Auto detect maximum column count, which can be written.
511+
* We assume that all characters, which were written, fit on the display.
512+
* Thus the maximum of the upperLeftColumnIndex after write is the index of the first column after the display and maximum possible column count.
513+
*/
514+
if (maximumColumns < upperLeftColumnIndex) {
505515
// find maximum column at runtime
506-
maximumColumnIndex = upperLeftColumnIndex;
516+
maximumColumns = upperLeftColumnIndex;
507517
}
508518

509519
/*
510-
* Implement the gap after the character
520+
* Implement the gap after the number character
511521
*/
512522
if (forceGapBetweenNumbers && (NumberWidth == 1 || tCharacterWidth > 1 || aNumberOrSpecialCharacter == '-')) {
513-
if (maximumColumnIndex != upperLeftColumnIndex) {
523+
if (maximumColumns >= upperLeftColumnIndex) {
514524
// We are not at the last column, so clear the gap after the number
515525
for (uint_fast8_t tRow = 0; tRow < NumberHeight; tRow++) {
516-
LCD->setCursor(upperLeftColumnIndex + 1, upperLeftRowIndex + tRow);
526+
LCD->setCursor(upperLeftColumnIndex, upperLeftRowIndex + tRow);
517527
LCD->write(' '); // Blank
518528
}
519529
tCharacterWidth++;
520530
}
521-
upperLeftColumnIndex++; // This provides one column gap between big numbers, but not between special characters.
531+
upperLeftColumnIndex++; // This provides one column gap between numbers, but not between special characters.
522532
}
523533

524534
#if defined(LOCAL_DEBUG)

0 commit comments

Comments
 (0)