hey guys i will connect oled ssh1106 with oxygen and pressure sensor to show the percent and i made 6 pages to show it with delay but the PROBLEM that i want to control the pages with 3 buttons ( up , down ,and select To navigate between pages and the first page will be data and clock ) if anyone help me with or modify it and here is the far i could go
#include <Wire.h>
#include <virtuabotixRTC.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
const unsigned char logo[] PROGMEM = {
};
virtuabotixRTC clock(3, 4, 2);
Adafruit_SH1106 display(-1);
int state = 1;
int currentPage = 1;
void setup()
{
pinMode(5, INPUT_PULLUP);
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
display.drawBitmap(0, 0, logo, 128, 64, WHITE);
display.display();
delay(2000);
drawUI();
}
void loop()
{
if (digitalRead(5) == LOW)
{
if (state == 0)
{
delay(500);
drawUI();
state = 1;
}
else
{
display.drawBitmap(0, 0, logo, 128, 64, WHITE);
display.display();
delay(2000);
state = 0;
currentPage = 1;
}
}
if (state == 1)
{
clock.updateTime();
drawUI();
displayData(currentPage);
display.display();
delay(10000);
currentPage = (currentPage % 5) + 1;
}
}
void drawUI()
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(2, 2);
display.println(" Clock Sleep");
display.drawLine(0, 11, 128, 11, WHITE);
display.drawLine(94, 0, 94, 10, WHITE);
display.drawLine(26, 44, 102, 44, WHITE);
}
void displayData(int page)
{
switch (page)
{
case 1:
display.setTextSize(1);
display.setCursor(2, 20);
display.print("O2:");
display.setCursor(40, 20);
display.print("70%");
display.setCursor(2, 35);
display.print("Flow:");
display.setCursor(40, 35);
display.print("5 L/min");
display.setCursor(2, 50);
display.print("Pressure:");
display.setCursor(50, 50);
display.print(" 10 cmH2O");
break;
case 2:
display.setTextSize(1);
display.setCursor(2, 20);
display.print("O2:");
display.setCursor(40, 20);
display.print("80%");
display.setCursor(2, 48);
display.print("Flow:");
display.setCursor(40, 48);
display.print("5 L/min");
break;
case 3:
display.setTextSize(1);
display.setCursor(2, 20);
display.print("Flow:");
display.setCursor(40, 20);
display.print("8 L/min");
display.setCursor(2, 48);
display.print("O2:");
display.setCursor(40, 48);
display.print("70%");
break;
case 4:
// Display pressure in cm H2O
display.setTextSize(1);
display.setCursor(2, 34);
display.print("Pressure:");
display.setCursor(80, 34);
display.print("cmH2O");
break;
case 5:
// Display pressure in mmHg
display.setTextSize(1);
display.setCursor(2, 34);
display.print("Pressure:");
display.setCursor(80, 34);
display.print("mmHg");
break;
}
}