I want to move some codes to another class and I am using an oled display. So when I move my code into another class, I can build without problem (I think somehow the compiler does not verify code before executing (aot).
so is there any thing that I should do? Because my arduino micro pro has problem with that. The computer does not recognise anymore unless if i do not reset.
I just add some basic codes.
my header file (OledDisplay.h)
#ifndef OledDisplay_h
#define OledDisplay_h
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Arduino.h"
class OledDisplay
{
public:
OledDisplay(uint16_t color,uint8_t size,uint16_t x, uint16_t y);
void ClearDisplay();
void SetTextColor(uint16_t color);
void SetTextSize(uint8_t size);
void SetCursor(uint16_t x, uint16_t y);
void PrintOneLine(String message,bool isDisplay);
void PrintTwoLinesMessage(String message1,int x0,int y0, String message2,int x1,int y1, bool clearDisplay);
private:
Adafruit_SSD1306 _display;
};
#endif
my cpp class OledDisplay.cpp
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#include "OledDisplay.h"
OledDisplay::OledDisplay(uint16_t color,uint8_t size,uint16_t x, uint16_t y)
{
_display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
ClearDisplay();
SetTextColor(color);
SetTextSize(size);
SetCursor(x,y);
_display.display();
}
void OledDisplay::ClearDisplay()
{
_display.clearDisplay();
_display.setCursor(0,0);
}
void OledDisplay::SetTextColor(uint16_t color)
{
_display.setTextColor(color);
}
void OledDisplay::SetTextSize(uint8_t size)
{
_display.setTextSize(size);
}
void OledDisplay::SetCursor(uint16_t x,uint16_t y)
{
_display.setCursor(x,y);
}
void OledDisplay::PrintOneLine(String message, bool isDisplay)
{
_display.print(message);
if(isDisplay)
_display.display();
}
void OledDisplay::PrintTwoLinesMessage(String message1,int x0,int y0, String message2,int x1,int y1, bool clearDisplay)
{
if(clearDisplay)
ClearDisplay();
SetCursor(x0,y0);
PrintOneLine(message1,false);
SetCursor(x1,y1);
PrintOneLine(message2,true);
}
both files in my library folder (I did not copy to programfiles, create a library flder in my D drive.)
and here how I am using the library
#include <OledDisplay.h>
OledDisplay _oledDisplay(WHITE,1,0,0);
void setup( )
{
_oledDisplay.PrintTwoLinesMessage("Welcome", 0,0,"bla bla bla", 0,20,true);
}
whats wrong with this code?