MAX30100 - problem with title

Hi I have a problem with my code,

I use the library for this sensor and the corresponding code, I was modifying the code just adding a while so that it measured my pulse only 17 times at the moment, now what I want is to activate the sensor with a case, but for my fortune when it I do in the case it does not give me the values and if I remove it from the case it pulls normal.

If someone could tell me where my mistake is or what I have to do I would appreciate it

// heart rate libraries --------------------------------
#include <Wire.h>
#include <EEPROM.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS     1000

// Heart pulse variables -------------------------------------
PulseOximeter pox;

uint32_t tsLastReport = 0;

int n2= 0;
int n3= 0;

int address = 0;
int direction2 = 1;

float pulse = 0;
float pulse2 = 0;

int i = 0;

char aux;
char b;

// function detect beat -------------------
void onBeatDetected()
{
  if(n2 < 17)
  {
   Serial.print(" ");
   n2=n2+1;
  }
    
}
//-------------------------------------------------------------
void setup()
{
  // start heart rate sensor
    Serial.begin(9600);

    Serial.print("Home pulse sensor ");

    if (!pox.begin()) {
        Serial.println("INCORRECT");
        for(;;);
    } else {
        Serial.println("CORRECT");
    }
}

// function of the cases
void loop(){

//switch(Serial.read())
      //{
       // case 'a':
        
        funcion_pulso_sat();
      
       // break;
  //}    
}

// heart rate function
void funcion_pulso_sat()
{
    while(n3 < 17){
      
        pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
        
        pox.setOnBeatDetectedCallback(onBeatDetected);
 
        pox.update();
 
    if (millis() - tsLastReport > REPORTING_PERIOD_MS){
          
        Serial.print("  SpO2:");
        Serial.print(pox.getSpO2());
        EEPROM.put(direccion2,pox.getSpO2());

        Serial.println(" %");

        pulso = pulso + pox.getHeartRate();
        pulso2 = pulso/15;
        
        Serial.print(" pulso2:");
        Serial.print(pulso2);
        EEPROM.put(direccion,pulso2);

        Serial.print(" ");
        Serial.print(tsLastReport);

        Serial.print(" ");
        Serial.print(REPORTING_PERIOD_MS);

           Serial.print(" m");
        Serial.print(millis());
        
        n3=n3+1;

        tsLastReport = millis();  
        
    }
    
  }
  
}