#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define GAS_SENSOR_PIN 2
void setup() {
Serial.begin(9600);
pinMode(GAS_SENSOR_PIN, INPUT);
delay(250); // wait for the OLED to power up
display.begin(i2c_Address, true); // Address 0x3C default
display.display();
delay(250);
//display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 0);
display.println("Failure is always an option");
display.setTextColor(SH110X_BLACK, SH110X_WHITE); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(SH110X_WHITE);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.display();
delay(2000);
display.clearDisplay();
display.drawPixel(10, 10, SH110X_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.println("Gas Monitor");
display.display();
}
void loop() {
int gasValue = analogRead(GAS_SENSOR_PIN);
float gasPercentage = (gasValue / 1024.0) * 100.0;
display.clearDisplay();
display.setCursor(0, 0);
display.print("Gas Level: ");
display.print(gasPercentage);
display.print("%");
display.display();
delay(1000);
}