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.

  • 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. – chrisl Feb 1 '20 at 0:09
  • Another answer of that question states, that you would need to do a transformation in the HSV color space. – chrisl Feb 1 '20 at 0:09

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.


To invert the display


To return the display again


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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.