Heart Rate Monitor

that's right, I should not reset it to 0, I just understand.

The code seems to work now when I detect the interrupt on "CHANGE" instead of "FALLING" but this would probably change if I used a schmitt trigger or the polar module from sparkfun that I've just ordered.

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, FALLING);                     //call pulse function when an interrupt is detected on Port 2;
  Serial.begin(9600);
}

void loop()
{
  static int fc;
  int frequence;
  if (beats > 1) {
    Serial.println(period, DEC);
    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;
    }
  }
  ssegment(fc);                                         //call ssegments function
}

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

void ssegment(int fc) {