|

Data Logger Oled SSD1306 I2C Pakai Library u8g2

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);

// Setup the terminal (U8G2LOG). No connection u8g2
// The size (width * height) depends on the selected font and the display

#define U8LOG_WIDTH 20
#define U8LOG_HEIGHT 6
uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT];
U8G2LOG u8g2log;


void setup(void) {
  u8g2.begin();
  u8g2log.begin(U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buffer);
  u8g2log.setLineHeightOffset(0);	// set extra space between lines in pixel, this can be negative
  u8g2log.setRedrawMode(0);		// 0: Update screen with newline, 1: Update screen for every char
}

unsigned long t = 0;

// print the output of millis() to the terminal every second
void loop(void) {

  // print something on the log window
  if ( t < millis() ) {
    t = millis() + 15000;			// every 15 seconds
    u8g2log.print("\f");			// \f = form feed: clear the screen
  }
  u8g2log.print("millis=");
  u8g2log.print(millis());
  u8g2log.print("\n");

  // print the log window together with a title
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_6x13_tr);		// font for the title
    u8g2.setCursor(0, 13);
    u8g2.print("Log Output: ");				// output title
    u8g2.setFont(u8g2_font_5x7_tr);			// set the font for the terminal window
    u8g2.drawLog(0, 23, u8g2log);			// draw the log content on the display
  } while ( u8g2.nextPage() );

  delay(500);
}

Hasil

Data Logger Oled SSD1306 I2C Pakai Library u8g2

Similar Posts