//=================================================================
// Project : Use I2C OLED 128x64
//
// Date : 2019-03-12
// Version : 1.0
//
// Note:
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY : without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
//
// Hardware
// 1. Arduino UNO
// 2. I2C OLED 128x64
// Libraries needed:
// https://github.com/adafruit/Adafruit_SSD1306
// https://github.com/adafruit/Adafruit-GFX-Library
//=================================================================
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
#include <Fonts/FreeMonoBold12pt7b.h> // Add a custom font
#include <Fonts/FreeMono9pt7b.h> // Add a custom font
Adafruit_SSD1306 oled;
#define SSD1306_I2C_ADR 0x3C
int change = 0;
void setup ()
{
Serial.begin(9600);
// OLED init
delay(100); // This delay is needed to let the display to initialize
oled.begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADR); // Initialize display with the I2C address of 0x3C
oled.clearDisplay(); // Clear the buffer
oled.setTextColor(WHITE); // Set color of the text
oled.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
oled.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
oled.dim(0); //Set brightness (0 is maximun and 1 is a little dim)
}
void loop ()
{
oled.clearDisplay(); // Clear the display so we can refresh
oled.setFont(&FreeMono9pt7b); // Set a custom font
oled.setTextSize(0); // Set text size. We are using a custom font so you should always use the text size of 0
oled.drawRect(0, 0, 128, 63, WHITE); // Draw rectangle (x,y,width,height,color)
// It draws from the location to down-right
oled.setCursor(10, 15); // (x,y)
oled.println("OLED Test"); // Text or value to print
oled.setCursor(20, 50);
if (change ==0)
oled.println("14:30:05");
else
oled.println("14:30:06");
oled.display(); // Print everything we set previously
delay(1000);
change = 1 - change;
}