1

I am trying to invert the color of my OLED display screen once a button is pushed. I have the button situation figured out but I can not find a function that inverts the color. I am using these two libraries to handle my screen on the Arduino IDE.

Adafruit_GFX.h, Adafruit_SSD1306.h

Any help would be much appreciated.

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jan 31, 2020 at 23:00
2
  • When there is no such function in these libraries, then there is most likely not an Adafruit function for that. You will have to do it yourself. It depends on what exactly means inverted here. koronas answer to this question on stackoverflow states, that you just need to invert the bits of the color components. The question is about C#, but the syntax in the answer is the same in C++. Please try, if that does, what you want. Commented Feb 1, 2020 at 0:09
  • Another answer of that question states, that you would need to do a transformation in the HSV color space. Commented Feb 1, 2020 at 0:09

1 Answer 1

3

There is a function that invert the colors of your screen, you can pick either black on white or white on black, I have tried it and I have quite experience with your display, I think you should try this piece of code.

At the beginning of your Arduino code be sure that you declared the object using the same name.

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

To invert the display

display.invertDisplay(true);

To return the display again

display.invertDisplay(false);

As you said that you want a button to invert the display you might use this code I made

if(digitalRead(BUTTON_PIN)){
 display.invertDisplay(true);
}
else{
 display.invertDisplay(false);
}

Or you might use Interrupts for better performance depending on your code.

As you couldn't find on the internet, I am student and I learn alot from the internet, to for example search for such a function in an Arduino library, try searching it's documentation or it's page on GitHub then afterwards see the function you want through the pages, but don't just search the function directly it will sometimes won't work as they are not that popular.

As a last thing Here is the documents where I got the function with it's parameters from.

I hope I've helped you out. any edits in the answer is well appreciated, as I am a student.

answered Feb 1, 2020 at 6:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.