|

Atur Kontras Oled SSD1306 I2C dengan u8g2 Library

Kode Program

/*
  Copyright (c) 2016, olikraus@gmail.com
  All rights reserved.
*/

#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);

void testContrast(uint8_t contrast) {
  static char cstr[6];
  static char vstr[4];
  u8g2.setContrast(contrast);
  strcpy(cstr, u8x8_u8toa(contrast, 3));
  u8g2.firstPage();
  do {
    //u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.setFont(u8g2_font_courB24_tn);
    u8g2.drawStr(0, 28, cstr);
    u8g2.drawBox(64, 0, 10, 64);
    u8g2.drawBox(76, 0, 2, 64);
    u8g2.drawBox(80, 0, 1, 64);
    u8g2.drawBox(82, 0, 1, 64);

    u8g2.drawBox(0, 32, 128, 10);
    u8g2.drawBox(0, 44, 128, 2);
    u8g2.drawBox(0, 48, 128, 1);
    u8g2.drawBox(0, 50, 128, 1);

  } while (u8g2.nextPage());
}

void setup(void) {
  u8g2.begin();
}

void loop(void) {
  uint8_t i;
  i = 255;
  do {
    testContrast(255 - i);
    delay(15);
    i -= 5;
  } while (i != 0);
  i = 255;
  delay(100);
  do {
    testContrast(i);
    delay(15);
    i -= 5;
  } while (i != 0);
  delay(100);
}

Hasil

Atur Kontras Oled SSD1306 I2C dengan u8g2 Library

Similar Posts