Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Oddity of OLEDDisplay.setColor(...)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Oddity of OLEDDisplay.setColor(...)

by droidxn on Fri Aug 21, 2020 9:39 am

Hi,

My first post here!

I am somewhat new to c/cpp and that could be the primary reason to this post.

This part of the code snippet works:
Code: Select all | TOGGLE FULL SIZE
SH1106Wire display(oledAddress, SDA, SCL);

// line is => struct line {float stX, float stY, float spX, float spY}
void eraseLine(line l)
{
    // This draws a black line resulting in erasing
    display.setColor(BLACK);
    display.drawLine(l.stX, l.stY, l.spX, l.spY);
    display.setColor(WHITE);
}


Now, I tried to move the code to a separate .cpp and .h file (BTW, I am using PlatformIO). So, I am passing the instance of the display (SH1106Wire) as a pointer.
Could this (passing pointer) be an issue?

Code: Select all | TOGGLE FULL SIZE
SH1106Wire display = SH1106Wire(oledAddress, SDA, SCL);

MyLib lib = MyLib();
lib.init(&display); // <- Is there a better way to pass the display. Note: Type here is SH1106Wire

// -- Code below are in MyClass.cpp
void MyLib::init(OLEDisplay *display){  // <- Could this be the problem. Note: Type here is OLEDdisplay
   _display = display;
   // ....
}
// ...
void eraseLine(line l)
{
    // This draws a black line resulting in erasing
    _display->setColor(BLACK);
    _display->drawLine(l.stX, l.stY, l.spX, l.spY);
    _display->setColor(WHITE);
}


I am baffled why the 1st piece of code works whereas the second piece (where I moved things to a lib doesn't. Drawing a WHITE (blue in my case) works fine in the lib but not erasing. Any suggestions?

droidxn
 
Posts: 1
Joined: Fri Aug 21, 2020 9:18 am

Please be positive and constructive with your questions and comments.