Merge code problem MAX30100 sensor and AD8232

sorry for my bad english

I am a college student, I want to make a medical device that can detect heartbeat, blood oxygen and heart rate. so, I use two main input components.

the first is max30100, I connect it to the oled display to display the output

the second is ad8232, processing IDE

I use Arduino Mega. after the circuit is complete,I tried to use each program for a component, to check the component and program will ran well

max30100

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"
#define REPORTING_PERIOD_MS 1000
OakOLED oled;

PulseOximeter pox;

uint32_t tsLastReport = 0;

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

void setup()
{
  Serial.begin(9600);

  oled.begin();
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 0);

  oled.println("Initializing pulse oximeter..");
  oled.display();
  Serial.print("Initializing pulse oximeter..");

  if (!pox.begin()) {
    Serial.println("FAILED");
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 0);
    oled.println("FAILED");
    oled.display();
    for (;;);
  } else {
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 0);
    oled.println("SUCCESS");
    oled.display();
    Serial.println("SUCCESS");
  }
  pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop()
{
  pox.update();

  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
    Serial.print("Heart BPM:");
    Serial.print(pox.getHeartRate());
    Serial.print("-----");
    Serial.print("Oxygen Percent:");
    Serial.print(pox.getSpO2());
    Serial.println("\n");
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 16);
    oled.println(pox.getHeartRate());

    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 0);
    oled.println("Heart BPM");

    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 30);
    oled.println("Spo2");

    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 45);
    oled.println(pox.getSpO2());
    oled.display();
    tsLastReport = millis();
  }
}

ad8232

void setup() {
  pinMode(10, INPUT);
  pinMode(11, INPUT);

}

void loop() {
  Serial.begin(9600);
  if ((digitalRead(10) == 1) || (digitalRead(11) == 1)) {
    Serial.println("Gagal");
  }
  else {
    Serial.println(analogRead(A1));
  }
  delay(10);
  Serial.end();
  delay(10);
}

when i use the code for max30100, i can see the output display on the oled display and when using code for ad8232, I can see the waveform on my computer monitor. I think this works well and I tried to merge two codes.

merge codes

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"
#define REPORTING_PERIOD_MS 1000
OakOLED oled;

PulseOximeter pox;
uint32_t tsLastReport = 0;

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

void setup()
{
  Serial.begin(9600);

  //================================LCD OLED======================//
  oled.begin();
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(1);
  oled.setCursor(0, 0);

  //================================MAX30100=====================//
  oled.println("Initializing pulse oximeter..");
  oled.display();
  Serial.print("Initializing pulse oximeter..");

  if (!pox.begin()) {
    Serial.println("FAILED");
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 0);
    oled.println("FAILED");
    oled.display();
    for (;;);
  } else {
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 0);
    oled.println("SUCCESS");
    oled.display();
    Serial.println("SUCCESS");
  }
  pox.setOnBeatDetectedCallback(onBeatDetected);

  //============================AD8232=========================//
  pinMode(10, INPUT);
  pinMode(11, INPUT);
}

void loop()
{
  //==========================MAX30100==========================//
  pox.update();

  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
    Serial.print("Heart BPM:");
    Serial.print(pox.getHeartRate());
    Serial.print("-----");
    Serial.print("Oxygen Percent:");
    Serial.print(pox.getSpO2());
    Serial.println("\n");
    oled.clearDisplay();
    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 16);
    oled.println(pox.getHeartRate());

    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 0);
    oled.println("Heart BPM");

    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 30);
    oled.println("Spo2");

    oled.setTextSize(1);
    oled.setTextColor(1);
    oled.setCursor(0, 45);
    oled.println(pox.getSpO2());
    oled.display();
    tsLastReport = millis();
  }

  //===================================AD8232=========================//
  Serial.begin(9600);
  if ((digitalRead(10) == 1) || (digitalRead(11) == 1)) {
    Serial.println("Gagal");
  }
  else {
    Serial.println(analogRead(A1));
  }
  delay(100);
  Serial.end();
  delay(100);
}

the result is that the oled display does not display anything and my monitor has no waveform, only the message "initializing pulse oximeter..FAILED"

I am a beginner but I understand some basic commands. I try my best to merge it.
Am I wrong in merge the two codes? please,can someone tell me my mistake.

thank