ssd1306 Oled i2c Arduino: How to clear only a part of the screen

Hello,

I would like to display several informations on a screen (ssd1306 Oled with an i2c protocole), and modify one of it without erasing the others.

I am using an Arduino uno, I found how to clear the buffer with the command “display.clearDisplay();”
My final objective is to keep the first character on the screen while the second is flashing.
I didn’t find the solution on the internet, maybe I just missunderstood how to do it…
This is the first time I publish something on this forum, did I forgot something about my problem ?

There is the code i am using (I modified the last word, basically I would like to print empty characters but I needed something visible to show the problem).

Thank you in advance

ssd_1306_oled_i2c_arduinouno.ino (931 Bytes)

If you only want to erase a small section of the screen, just draw a BLACK filled rectangle.

If you are writing text, it is probably easier to draw spaces. Then reposition the cursor.
Or simply overwrite the previous text. Perhaps with some trailing spaces to rub out any previous text.

Note that setTextColor(WHITE, BLACK) will overwrite the screen with fresh text on a fresh background.

David.

It doesn't work with spaces (it doesn't overwrite the text), but it will be fine if I just add a black text to overwrite the first one. I didn't know it was possible to change the color.

Thank you very much,

Quentin

I just tried your sketch with:

    ...
    display.setTextColor(WHITE, BLACK);
    ...
        ...
        display.print("test ");

It does what you want.

David.

The setTextColor(WHITE,BLACK) worked perfectly for me. I overwrite data from a DHT temp/humidity sensor in a specific location. It now overwrites cleanly. Thanks for the tip.