Hi everyone and thank you for taking the time to read this.
I am working on a diy music machine which has an oled display that I am driving using the u8g2 library.
I have started writing a class for the UI and I am trying to use u8g2 methods straight from it to write to the display but I am getting an error when compiling:
I am going insane because I got it working yesterday, I'm pretty sure I remember using a "u8g2_t" type somewhere instead of "U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI" but today I did too many undos then erased a line and now my redo options are gone and I can't figure out for the life of me what trickery I'd used.
Here is what my basic knowledge of cpp made me write:
I have been ripping my hair out for hours. I found this post on the devil's website but it didn't work for me (I did adapt it to my case, like changing u8x8 to u8g2 and changing the class name and the constructor to match my display).
Please help me!
I am working on a diy music machine which has an oled display that I am driving using the u8g2 library.
I have started writing a class for the UI and I am trying to use u8g2 methods straight from it to write to the display but I am getting an error when compiling:
Code:
/home/mrfry/Arduino/libraries/ui/UI.cpp:6:55: error: no matching function for call to 'U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI::U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI()'
I am going insane because I got it working yesterday, I'm pretty sure I remember using a "u8g2_t" type somewhere instead of "U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI" but today I did too many undos then erased a line and now my redo options are gone and I can't figure out for the life of me what trickery I'd used.
Here is what my basic knowledge of cpp made me write:
Code:
// groovebox_ui.ino
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <UI.h>
U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI u8g2(U8G2_R0, 10, 9, 8); // Instantiate u8g2
UI UI(u8g2); // Instantiate my lib passing the u8g2 object as an argument
// [a mess of other stuff waiting to be "librarised" as well]
void setup(void) {
}
void loop(void) {
UI.drawScreen();
// [redacted stuff]
}
Code:
//ui.h
#ifndef LIBRARIES_UI_UI_H_
#define LIBRARIES_UI_UI_H_
#include "Arduino.h"
#include <U8g2lib.h>
class UI {
public:
U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI _display; // Create a variable of the same type as my display to hold my display
// [some more member variables and methods]
UI(U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI display); // Declare my constructor
};
#endif /* LIBRARIES_UI_UI_H_ */
Code:
#include <UI.cpp>
UI::UI(U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI display) { // Define my constructor
_display = display;
_display.begin();
// [other constructor stuff]
}
void UI::drawScreen() {
_display.clearBuffer();
// [drawing methods]
_display.sendBuffer();
}
I have been ripping my hair out for hours. I found this post on the devil's website but it didn't work for me (I did adapt it to my case, like changing u8x8 to u8g2 and changing the class name and the constructor to match my display).
Please help me!
Last edited: