Oled clock with pulseoximeter and thermostat

im making a pulse oximeter, thermometer and clock 3 in 1. I'm using an arduino uno r3. Here is my code.

#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000  
RTC_DS3231 rtc;
Adafruit_SH1106 display(-1);
int state = 1;

const int lm35_pin = A1;

PulseOximeter pox;

uint32_t tsLastReport = 0;

void onBeatDetected() {
  Serial.println("Beat!");
}

void drawUI() {
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(2, 2);
  display.println("Digital Clock ON");
  display.drawLine(0, 11, 128, 11, WHITE);
  display.drawLine(94, 0, 94, 10, WHITE);
  display.drawLine(26, 44, 102, 44, WHITE);
}

void setup() {
  pinMode(5, INPUT_PULLUP);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.display();

  if (!rtc.begin()) {
    Serial.println("No RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  Serial.begin(9600);
  Serial.print("Initializing pulse oximeter..");

  if (!pox.begin()) {
    Serial.println("FAILED");
    for (;;);
  } else {
    Serial.println("SUCCESS");
  }

  pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
  pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {
  pox.update();

  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
    Serial.print(F("Heart rate:"));
    Serial.print(pox.getHeartRate());
    Serial.print(F("bpm / SpO2:"));
    Serial.print(pox.getSpO2());
    Serial.println(F("%"));

    tsLastReport = millis();
  }

  int temp_adc_val;
  float temp_val;
  temp_adc_val = analogRead(lm35_pin);
  temp_val = (temp_adc_val * 4.88);
  temp_val = (temp_val / 10);
  Serial.print(F("Temperature = "));
  Serial.print(temp_val);
  Serial.print(F(" Degree Celsius\n"));

  if (digitalRead(5) == LOW) {
    if (state == 0) {
      delay(500);
      drawUI();
      state = 1;
    } else {
      delay(500);
      display.drawRect(4, 7, 120, 50, WHITE);
      display.fillRect(5, 8, 118, 48, BLACK);
      display.setTextSize(1);
      display.setCursor(6, 12);
      display.println("Clock turn");
      display.println(" off in a moment.");
      display.println("");
      display.println(" To turn back on,");
      display.println(" press button.");
      display.display();
      delay(3000);
      display.clearDisplay();
      display.display();
      state = 0;
    }
  }

  if (state == 1) {
    DateTime now = rtc.now();
    drawUI();
    display.setTextColor(WHITE);
    display.setTextSize(3);
    display.setCursor(1, 19);
    if (now.hour() < 10) {
      display.print("0");
    }
    display.print(now.hour());
    display.print(":");
    if (now.minute() < 10) {
      display.print("0");
    }
    display.print(now.minute());
    display.setTextSize(2);
    display.print(":");
    if (now.second() < 10) {
      display.print("0");
    }
    display.print(now.second());
    display.setTextSize(1);
    display.setCursor(26, 48);
    switch (now.dayOfTheWeek()) {
      case 1: display.print("Monday,"); break;
      case 2: display.print("Tuesday,"); break;
      case 3: display.print("Wednesday,"); break;
      case 4: display.print("Thursday,"); break;
      case 5: display.print("Friday,"); break;
      case 6: display.print("Saturday,"); break;
      case 7: display.print("Sunday,"); break;
    }
    display.setCursor(26, 56);
    if (now.day() < 10) {
      display.print("0");
    }
    display.print(now.day());
    display.print(".");
    if (now.month() < 10) {
      display.print("0");
    }
    display.print(now.month());
    display.print(".");
    display.print(now.year());
    display.display();
    delay(999);
  }
}

instead of showing the coded clock, it just show this:

The clock alone works fine. only when i integrate it with my pulse+thermostat code it did not work

Zero comments............. :confused:

Have you tried each device individually... like you did with the clock... do the same with the MAX3010x.

You should delete your duplicate topic and keep this one... the other one has zero activity.

Hi @finally_over,

welcome to the arduino-forum.

Programming is a complex thing. Users could do an analyse of your code and then write a lot of unproven guessings what might be wrong or right. But this is very inefficient.

The forum members will help. Most likely that posters that show own effort and provide detailed information.

You can speed up making your project work if you provide more information.
The code you have posted prints to the serial monitor.

This serial printing will give first hints what is going on.
You should add even more serial printing to your code to make visible what the code is really doing.

If you don't know how to do that. Just ask. Again If you would have already provided information about your programming-skills a taylored to your knowledge answer could have been posted.

I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

best regards Stefan

I have deleted your other cross-post @finally_over.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.