#include <U8g2lib.h>
#include <Wire.h>
#include "Button.h"
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
Button Button_1(13);
Button Button_2(12);
Button Button_3(11);
String cuan[3];
void setup() {
cuan[0] = "123";
cuan[1] = "456";
cuan[2] = "789";
Button_1.begin();
Button_1.set_repeat(500, 200);
Button_2.begin();
Button_2.set_repeat(500, 200);
Button_3.begin();
Button_3.set_repeat(500, 200);
u8g2.setI2CAddress(0x3C * 2);
u8g2.begin();
u8g2.enableUTF8Print();
}
int page_num = 0;
void loop() {
if (Button_1.pressed()) {
if(page_num>=3) page_num= 0;
page_num++;
}
if (Button_2.pressed()) {
page_num = 2;
}
if (Button_3.pressed()) {
page_num = 3;
}
u8g2.firstPage();
do
{
page1(page_num);
} while (u8g2.nextPage());
}
void page1(int num) {
u8g2.setFont(u8g2_font_timR12_tf);
u8g2.setFontPosTop();
u8g2.setCursor(0, 00);
u8g2.print(cuan[0]);
u8g2.setCursor(0, 20);
u8g2.print(cuan[1]);
u8g2.setCursor(0, 40);
u8g2.print(cuan[2]);
if (num == 1) {
u8g2.setFont(u8g2_font_timB14_tf);
u8g2.setFontPosTop();
u8g2.setCursor(0, 00);
u8g2.print(cuan[num-1]);
} else if (num == 2) {
u8g2.setFont(u8g2_font_timB14_tf);
u8g2.setFontPosTop();
u8g2.setCursor(0, 20);
u8g2.print(cuan[num-1]);
} else if (num == 3) {
u8g2.setFont(u8g2_font_timB14_tf);
u8g2.setFontPosTop();
u8g2.setCursor(0, 40);
u8g2.print(cuan[num-1]);
}
}