How to set the brightness on OLED display with SSD1306

Goto => Seed-Studio: http://wiki.seeedstudio.com/Grove-OLED_Display_0.96inch (description) and
Download => https://github.com/Seeed-Studio/OLED_Display_128X64/archive/master.zip (library) !


How to fade in or fade out OLED Display SSD1306 with Adafruit library -!!!

(see nl-modified «= here !)

This is how I created a fade in and fadeout commands to Adafruit SSD1306 library.
It changes both SSD1306_SETCONTRAST and SSD1306_SETPRECHARGE to give a nice fade out.

How to:

In Adafruit_SSD1306.h, after

"void display();" add:

void fadeout();
void fadein();

In Adafruit_SSD1306.cpp, after

"ssd1306_command(SSD1306_DISPLAYON); //-turn on oled panel
 }"
add:


void Adafruit_SSD1306::fadeout() {
for (int dim=150; dim>=0; dim-=10) {
ssd1306_command(0x81);
ssd1306_command(dim); //max 157
delay(50);
}


for (int dim2=34; dim2>=0; dim2-=17) {
ssd1306_command(0xD9);
ssd1306_command(dim2);//max 34
delay(100);
}
}

void Adafruit_SSD1306::fadein() {
for (int dim=0; dim<=160; dim+=10) {
ssd1306_command(0x81);
ssd1306_command(dim); //max 160
delay(50);
}


for (int dim2=0; dim2<=34; dim2+=17) {
ssd1306_command(0xD9);
ssd1306_command(dim2);//max 34
delay(100);
}
}

Hope it helps.


nl-modified:

// ------------- dazu -------------
void Adafruit_SSD1306::dimm() { //fadeout
// for (int dim=150; dim>=0; dim-=10) {
ssd1306_command(0x81);
ssd1306_command(0); //max 157 - 0
delay(20);

// for (int dim2=34; dim2>=0; dim2-=17) {
ssd1306_command(0xD9);
// ssd1306_command(dim2); //max 34 - 0
ssd1306_command(0);
delay(40);
}

void Adafruit_SSD1306::dimp() { //fadein
// for (int dim=0; dim<=160; dim+=10) {
ssd1306_command(0x81);
ssd1306_command(160); //max 160
delay(20);

// for (int dim2=0; dim2<=34; dim2+=17) {
ssd1306_command(0xD9);
ssd1306_command(34);//max 34
delay(40);
}
// ------------- dazu Ende -------------