#include <U8g2lib.h>
#include <Wire.h>
volatile float Threshold;
volatile float item;
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
void page1() {
u8g2.setFont(u8g2_font_timR12_tf);
u8g2.setFontPosTop();
u8g2.setCursor(0,20);
u8g2.print(String("CO value:") + String(String(item)) + String(" % "));
}
void setup(){
Threshold = 50;
item = 0;
u8g2.setI2CAddress(0x3C*2);
u8g2.begin();
u8g2.enableUTF8Print();
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
}
void loop(){
item = (map(analogRead(A0), 1, 1024, 1, 100));
u8g2.firstPage();
do
{
page1();
}while(u8g2.nextPage());
if (item >= Threshold) {
digitalWrite(13,HIGH);
} else {
digitalWrite(13,LOW);
}
}