I am currently working on refactoring both the menu and code for the wire cutting machine I built a year and a half ago.
The issue for today is to tackle the extremely redundant way I handled printing pages to the LCD.
For Example:
void printIntro(void)
{
lcd.clear();
lcd.setCursor (6, 0);
lcd.print(F("WireBot!"));
lcd.setCursor (4, 1);
lcd.print(F("An Automatic"));
lcd.setCursor (2, 2);
lcd.print(F("Wire Cutting and"));
lcd.setCursor (0, 3);
lcd.print(F("Stripping Machine!!!"));
} // End printIntro()
void printStartScreen(void)
{
lcd.clear();
lcd.setCursor (3, 0);
lcd.print (F("WireBot READY!"));
lcd.setCursor (3, 2);
lcd.print (F("Press any key"));
lcd.setCursor (6, 3);
lcd.print (F("to begin"));
} // End printStartScreen()
And here is a complete MCVE of my current attempt to refactor this to eliminate redundancy and hopefully free up some program space(I have plenty of RAM).
#include <Wire.h>
#include <hd44780.h> // main hd44780 header - v.1.2.0 https://github.com/duinoWitchery/hd44780
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
// LCD Pins are automatically detected in software. Uses I2C(pins A4, A5)
constexpr uint8_t LCD_COLS = 20;
constexpr uint8_t LCD_ROWS = 4;
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
// Intro Page
constexpr int8_t introRow1[] = "WireBot!";
constexpr int8_t introRow2[] = "An Automatic";
constexpr int8_t introRow3[] = "Wire Cutting and";
constexpr int8_t introRow4[] = "Stripping Machine!!!";
// Start Page
constexpr int8_t startRow1[] = "WireBot READY!";
constexpr int8_t startRow2[] = "";
constexpr int8_t startRow3[] = "Press any key";
constexpr int8_t startRow4[] = "to begin";
constexpr int8_t* menuPages[][LCD_ROWS] {
{introRow1, introRow2, introRow3, introRow4}, // Intro Page
{startRow1, startRow2, startRow3, startRow4} // Start Page
};
constexpr uint8_t curPos [][LCD_ROWS] {
{6, 4, 2, 0}, // Intro Page
{3, 0, 3, 6} // Start Page
};
enum : uint8_t {
INTRO_PAGE,
START_PAGE
};
void printPage(uint8_t page) {
lcd.clear();
for ( int i = 0; i < LCD_ROWS; i++) {
lcd.setCursor (curPos [page][i], i);
lcd.print(*menuPages[page][i]);
}
}
void setup() {
lcd.begin(LCD_COLS, LCD_ROWS);
printPage(INTRO_PAGE);
delay(2500);
printPage(START_PAGE);
}
void loop() {
// put your main code here, to run repeatedly:
}
The problem is that it is printing integers where it should be printing my strings. My guess is that these are the memory address' or maybe just random garbage IDK. Either way it's obvious I'm not handling the pointer properly.