Function for changing the brightness on a OLED screen from an Arduino 96 in (inches) display (SSD1306)

Tiempo de lectura: < 1 minuto

We bring you a function that allows to reduce the brightness of the OLED SSD1306 screen connected to our Arduino.

Palmeras noche - Pexels

We add this code using the Adafruit library:

adafruit/Adafruit SSD1306@^2.5.7
adafruit/Adafruit GFX Library@^1.11.9

We create this function:

void OledDisplay::brightness(uint8_t level)
{
    display.ssd1306_command(SSD1306_SETCONTRAST);
    display.ssd1306_command(level);
}

We can add values in the range: 0-255

For level = 255, all pixels turn on → maximum brightness.

For level = 127, about half will be lit -> average brightness.

For level = 20, few points will light up -> very dim.

Leave a Comment