#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// made function textLine to format and print to LCD
// test on hardware with padding strings in progmem
// added overloaded function to print numeric values
// for presets
char leftBuffer[17];
char numBuffer[10];
char preset[] = "preset";
char name[] = "name";
char dog[] = "dog";
char letter[] = "letter";
char fill[] = " ";
int r;
const uint8_t topLine = 0;
const uint8_t bottomLine = 1;
char spacePadding[7][7] = {
" ", " ", " ", " ", " ", " ", " "
};
char charPadding[7][7] = {
".", "...", "...", "....", ".....", "......", "......."
};
void setup() {
Serial.begin(115200);
int sum = 16;
lcd.init();
lcd.backlight();
//textLine(topLine, letter, name);
//delay(20);
//textLine(bottomLine, name, preset);
// delay(3000);
textLine(bottomLine, letter, "number");
textLine(topLine, preset, 351);
}
void textLine(uint8_t line, char* leftText, char* rightText) {
byte sum = 15;
sum -= strlen(leftText);
sum -= strlen(rightText);
lcd.setCursor(0, line);
leftBuffer[0] = '\0'; // clear text buffer
snprintf(leftBuffer, "%-s", leftText); // insert left-justified text
strlcat(leftBuffer, spacePadding[sum ], 17);
strlcat(leftBuffer, rightText, 17);
lcd.print(leftBuffer);
}
// overloaded function
void textLine(uint8_t line, char* leftText, uint16_t numValue) {
byte sum = 15;
snprintf(numBuffer, 10, "%6d", numValue);
sum -= strlen(leftText);
sum -= strlen(numBuffer);
lcd.setCursor(0, line);
leftBuffer[0] = '\0'; // clear text buffer
snprintf(leftBuffer, "%-s", leftText); // insert left-justified text
strlcat(leftBuffer, spacePadding[sum ], 17);
strlcat(leftBuffer, numBuffer, 17);
lcd.print(leftBuffer);
}
void loop() {
// put your main code here, to run repeatedly:
}