*SOLVED* Pointer problems

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.

Not sure if it's the only problem. But, if you want to print characters, why are you defining them as integer types?

Instead of this:

constexpr int8_t introRow1[] = "WireBot!";

Try this:

constexpr char introRow1[] = "WireBot!";

Because I had thought that int8_t was another way of declaring a char, but changing them results in it printing the first character of each string. It's a start.

#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 char introRow1[] = "WireBot!";
constexpr char introRow2[] = "An Automatic";
constexpr char introRow3[] = "Wire Cutting and";
constexpr char introRow4[] = "Stripping Machine!!!";

// Start Page
constexpr char StartRow1[] = "WireBot READY!";
constexpr char StartRow2[] = "";
constexpr char StartRow3[] = "Press any key";
constexpr char StartRow4[] = "to begin";

constexpr char* 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:

}
    lcd.print(*menuPages[page][i]);

You do not need the '*'.

Well before I changed the int8_t's to char it wouldn't compile without the '*' but it does now and is working fine.

Thank you both.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.