#include #include #include #include #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_ADDR 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); Adafruit_BME280 bme; // your SEN0236 sensor // Buttons / touch pins as digital inputs #define PIN_UP 2 #define PIN_DOWN 3 #define PIN_SELECT 20 // now with pull-up const int debounceDelay = 200; // ms unsigned long lastPress = 0; // Menu items const char* menuItems[] = {"Show Temp", "Show Humidity", "Show Pressure", "Test Output"}; const int menuLength = 4; int selected = 0; void setup() { Serial.begin(115200); Wire.begin(6, 7); // I2C SDA/SCL for OLED + BME280 // Buttons: UP/DOWN normal, SELECT with internal pull-up pinMode(PIN_UP, INPUT); pinMode(PIN_DOWN, INPUT); pinMode(PIN_SELECT, INPUT_PULLUP); // OLED init if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { Serial.println("SSD1306 init failed"); while (1); } display.clearDisplay(); display.setTextColor(SSD1306_WHITE); // BME280 init if (!bme.begin(0x77)) { Serial.println("BME280 not found!"); while (1); } } void loop() { handleInput(); drawMenu(); delay(50); } void handleInput() { unsigned long now = millis(); if (now - lastPress < debounceDelay) return; // UP button if (digitalRead(PIN_UP)) { selected--; if (selected < 0) selected = menuLength - 1; Serial.println("UP pressed"); lastPress = now; } // DOWN button if (digitalRead(PIN_DOWN)) { selected++; if (selected >= menuLength) selected = 0; Serial.println("DOWN pressed"); lastPress = now; } // SELECT button (active LOW) if (digitalRead(PIN_SELECT) == LOW) { Serial.print("SELECT: "); Serial.println(menuItems[selected]); runAction(selected); lastPress = now; } } void drawMenu() { display.clearDisplay(); // Header display.setCursor(0, 0); display.setTextSize(1); display.println("MENU"); for (int i = 0; i < menuLength; i++) { int y = 16 + (i * 10); display.setCursor(0, y); if (i == selected) display.print("> "); else display.print(" "); display.println(menuItems[i]); } display.display(); } void runAction(int index) { display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1); switch (index) { case 0: Serial.println("Temp selected"); display.println("Temp selected"); break; case 1: Serial.println("Humidity selected"); display.println("Humidity selected"); break; case 2: Serial.println("Pressure selected"); display.println("Pressure selected"); break; case 3: Serial.println("Test output triggered"); display.println("Test OK"); break; } display.display(); delay(1000); }