#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, 43, 44, U8X8_PIN_NONE);
const int potPin = 13;
void setup(){
Serial.begin(115200);
u8g2.setI2CAddress(0x3C * 2);
u8g2.begin();
u8g2.enableUTF8Print();
analogReadResolution(12);
}
void loop(){
int adcValue = analogRead(potPin);
float voltage = adcValue * (3.3 / 4095.0);
float angle = (adcValue * 270.0) / 4095.0;
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_wqy12_t_gb2312);
u8g2.setFontPosTop();
u8g2.setCursor(0, 4);
u8g2.print("模拟量数值: ");
u8g2.print(adcValue);
u8g2.setFont(u8g2_font_wqy16_t_gb2312);
u8g2.setCursor(0, 24);
u8g2.print("电压: ");
u8g2.print(voltage, 2);
u8g2.print("V");
u8g2.setCursor(0, 44);
u8g2.print("角度: ");
u8g2.print(angle, 1);
u8g2.print("°");
} while(u8g2.nextPage());
delay(5);
}