Thank you for this nice idea! I've try it but it does not seem to work, although some things were not working properly, I made somage changes to make it theorically working but it doesn't, here it is:
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;
beats = 0;
}
lastTime = millis();
beats++;
}
}
void ssegment(int fc) {