Hello! I'm writing my own library and I need to control an 128x64 I2C display. I've choosed Adafruit_SSD1306.h one. I made a class what will keep functions for my needs.
But I suddenly caught a problem that Arduino Mega 2560 Pro (which I'm using for my project) freezes when I declare an Adafruit_SSD1306 object inside a class (as it's member). It happens when I just declare my class' object (and also a member object), not when initializing those.
//.h
class Display
{
private:
Adafruit_SSD1306 display;
public:
Display();
void clear();
void update();
void drawLine(uint8_t, uint8_t, uint8_t, uint8_t, bool);
void drawRect(uint8_t, uint8_t, uint8_t, uint8_t, bool, bool);
void drawCircle(uint8_t, uint8_t, uint8_t, bool, bool);
void drawTriangle(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, bool, bool);
void drawText(String, uint8_t, uint8_t);
void drawText(String, uint8_t, uint8_t, uint8_t, bool);
void drawInverse(uint8_t, uint8_t, uint8_t, uint8_t);
};
//.cpp
Display::Display()
{
this->display = Adafruit_SSD1306(128, 64);
this->display.begin();
this->clear();
this->drawText("Display!", 0, 0);
this->update();
}
void Display::clear() { this->display.clearDisplay(); }
void Display::update() { this->display.display(); }
//...some other functions