I made a little class for handling menus. When creating a new instance, I pass a reference to the oled
object made in main.cpp
. Yet when I want to render a string using a variable, it throws an error. But I can pass a string directly to the render function with no problems. See comments in the code for what is working and what is not.
#include "Arduino.h"
#include "U8glib.h"
#pragma once
class Menu {
U8GLIB_SSD1306_128X64& oled;
public:
Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
this->oled = oled;
};
void render() {
this->oled.firstPage();
do {
String text = "test2";
this->oled.setFont(u8g_font_unifont);
this->oled.setPrintPos(0, 20);
this->oled.drawStr(text); // not working
this->oled.drawStr(text.c_str()); // not working
this->oled.drawStr("works"); // works
} while (this->oled.nextPage());
}
};
In the case of this->oled.drawStr(text);
the error is:
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)
In case of this->oled.drawStr(text.c_str())
the error is:
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)
How I create the instance in main.cpp
:
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();
drawStr
function in the current U8glib library that takes only one parameter. What version are you using and where did you get it?