Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change the HeartRateSensor frequency

I have a clockface that reads the heart rate bpm every 8 seconds and stores it in an array so I can draw a graph of the my heart rate for the past 10 minutes.

 

I initiate the sensor with const hrm = new HeartRateSensor({ frequency: 8 });

 

In addition to populating the array every 8 seconds, I would like to read the hrm.heartRate in order to populate a text field. But I would like to do this every second.

 

So my question is, how can I make the frequency of hrm 8 when the display is off, and change it to 1 when the display is on? Is it simply a case of hrm.frequency = 1?

Best Answer
0 Votes
5 REPLIES 5
Best Answer
0 Votes

Thanks @JonFitbit  Interestingly, although I initiate the sensor with frequency: 8, I'm still able to get varying heartRate values far more frequently than 8 seconds, for example if I read them on the clock tick. Likewise, if I use the code below, I'll get an almost continuous stream of values

 

hrm.addEventListener("reading", () => {
    console.log(`Current heart rate: ${hrm.heartRate}`);
  });

 

Could you please clarify what the frequency option is actually doing?

Best Answer
0 Votes

Ah, I think I see my misunderstanding. Frequency is not seconds between readings, it's the number of readings per second (hz)! 

Best Answer

I know you're not talking to me, but I think the answer is that the frequency just sets how often your event handler (callback) function is called. You'll probably find that readings only change every three seconds or so, at best.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Yes, thanks Gondwana. I realised my error just after posting. Of course, the clue is in the word "frequency"!

Best Answer
0 Votes