Heart Rate Monitor

Francis, I have not run this code but here are some ideas for simplifying your sketch

int  D3 = 3, D4 = 4, D5 =5, D6 = 6, D7 = 7, D8 = 8;
volatile unsigned long beats = 0, lastTime, period;


void setup()
{
  pinMode(D3, OUTPUT);                                   //P3 to P8 as output
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
  pinMode(D8, OUTPUT);
  attachInterrupt(0, pulse, RISING);                     //call pulse function when an interrupt is detected on Port 2;  
}

void loop()
{
  static int fc;
  int frequence;
  if (beats > 1) {
    frequence = (60000 / period);         //calculate bpm using time between the two pulses
    if ((frequence >= 40) && (frequence <= 220)) {   //if bpm is between 40 and 220
      fc = frequence;
    }
  }
  ssegments(fc);                                         //call ssegments function                                  
}

void pulse()
{
  if (beats > 0){
    period =  millis() - lastTime;
    beats++;
  }
  lastTime = millis();
}


void ssegments(int fc) {  
// rest of code is unchanged
}