/*
U8g2 GitHub Reference Manual
Examples of all draw functions
*/
#include <U8g2lib.h>
/********** Use with u8g2 mode, '1', '2' or 'F' for buffer size, 'HW' hardware 12C **********/
// Below is the 'constructor' from u8g2setupcpp setup guide
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C(rotation, [reset [, clock, data]]) [page buffer, size = 128 bytes]
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0);
// 'icon_battery', 16x16px
const unsigned char Battery_Icon[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0x02, 0x20, 0xda, 0x66, 0xda, 0x66,
0xda, 0x66, 0x02, 0x20, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup(void) {
// u8g2.begin() set the init sequence to the display
u8g2.begin();
}
void loop(void) {
/*
// Full buffer mode (F) fast, but uses alot of memory
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB14_tr);
u8g2.drawStr(0,24,"Hello World!");
u8g2.sendBuffer();
*/
// Page buffer mode (1) all graphics supported, slow, uses less memory
/*
Page size is 8 pixels x 128 pixels. First 'page' is taken from the buffer and
drawn on the oled. Code moves to 'nextPage' and is repeated 8 times until all
pages are displayed on the oled. (8 pixels x 8 pages = 64 pixels)
*/
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_cupcakemetoyourleader_tr);
// draw text string
u8g2.drawStr(0, 12, "Hello World!");
// draw box
u8g2.setDrawColor(1);
u8g2.drawBox(0, 16, 25, 15);
// draw button
u8g2.setFont(u8g2_font_helvR08_tr);
u8g2.drawButtonUTF8(33, 26, U8G2_BTN_BW2, 0, 2, 2, "Btn");
u8g2.drawButtonUTF8(74, 26, U8G2_BTN_SHADOW1|U8G2_BTN_HCENTER|U8G2_BTN_BW2, 24, 2, 2, "Btn");
u8g2.drawButtonUTF8(101, 26, U8G2_BTN_INV|U8G2_BTN_BW2, 0, 2, 2, "Btn");
// draw circle, can also draw 1/4 circles, example: U8G2_DRAW_UPPER_RIGHT
u8g2.drawCircle(10, 48, 10, U8G2_DRAW_ALL);
// draw disc, can also draw 1/4 disc, example: U8G2_DRAW_UPPER_RIGHT
u8g2.drawDisc(35, 48, 10, U8G2_DRAW_ALL);
// draw ellipse, can also draw 1/4 ellipse, example: U8G2_DRAW_UPPER_RIGHT
u8g2.drawEllipse(65, 48, 15, 10, U8G2_DRAW_ALL);
// draw filled ellipse, can also draw 1/4 ellipse, example: U8G2_DRAW_UPPER_RIGHT
u8g2.drawFilledEllipse(100, 48, 15, 10, U8G2_DRAW_ALL);
} while (u8g2.nextPage());
delay(4000);
u8g2.clearDisplay();
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_crox3h_tr);
u8g2.drawStr(0, 12, "Page 2");
// draw unfilled box
u8g2.drawFrame(0, 17, 25, 15);
//draw glyph
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(30, 30, 0x2603); // dec 9731/hex 2603 Snowman
u8g2.drawGlyph(50, 30, 0x2615);
// draw horizontal line
u8g2.drawHLine(70, 18, 15);
u8g2.drawHLine(70, 23, 15);
u8g2.drawHLine(70, 28, 15);
// draw line between two x/y points
u8g2.drawLine(90, 30, 95, 0);
u8g2.drawLine(93, 30, 105, 0);
u8g2.drawLine(96, 30, 115, 0);
u8g2.drawLine(99, 30, 125, 0);
u8g2.drawLine(102, 30, 135, 0); // 135 is outside of 128 pixal width, but will assume location
// draw pixel, four pixels drawn inside of box
u8g2.drawPixel(3, 20);
u8g2.drawPixel(21, 20);
u8g2.drawPixel(3, 28);
u8g2.drawPixel(21, 28);
// draw radius corner box
u8g2.drawRFrame(0, 35, 25, 15, 5);
// draw triangle, ()
u8g2.drawTriangle(0,50, 0,64, 30,64);
// draw verticle line
u8g2.drawVLine(30, 35, 15);
u8g2.drawVLine(35, 35, 15);
u8g2.drawVLine(40, 35, 15);
// draw battery icon bitmap, use XBMP, does not work with XBM
u8g2.drawXBMP( 45, 35, 16, 16, Battery_Icon);
// There are many 'get' functions, see u8g2 reference manual
u8g2.setFont(u8g2_font_crox3h_tr);
u8g2.setCursor(35, 64); // set curson position
u8g2.print(u8g2.getAscent()); // prints to curser position
u8g2.print(u8g2.getDescent());
// set 'brightness' of display, 0 to 255
u8g2.setContrast(255);
} while (u8g2.nextPage());
delay(4000);
u8g2.clearDisplay();
}