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

heart rate monitor alert on intervals

ANSWERED

Hi there,

I am playing around with the heart rate monitor app for my Fitbit Ionic, which shows heart rate every second. I want to make so if heart rate goes below a certain level, vibrate is turned on as an alert. I want this to be done every 3minutes. So the HR is monitored every second BUT the alert is monitored every 3minutes and when I press any of the side buttons on my ionic, the alert vibration should stop.

right now I have it as if the heart rate goes below 60, the vibrate is turned on but I don't know how to attach it to a button that will shut it off for 3minutes. Any help would be appreciated. Thanx in advance

 if (hrm.heartRate < 60)
{
  vibration.start("ring");
}
  document.onkeypress = function(e)
{

  console.log("Key pressed: " + e.key);
  vibration.stop()
}
}
SN
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Sorry, looks like it was slightly wrong. It's using modulo https://stackoverflow.com/questions/16505559/how-can-i-use-modulo-operator-in-javascript

 

That should have been

(today.getMinutes() % 3) === 0

You can see it in action here: https://jsfiddle.net/xz7a0gdf/3/

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

Something like:

 

 

let timer;

function heartAlert() {
vibration.start("ring");
}

document.onkeypress = function(e) {
vibration.stop();
clearInterval(timer);
}

// inside tick event?
if (hrm.heartRate < 60 && today.getMinutes() % 3 && !timer) {
timer = setInterval(heartAlert, 1000); // every second
}

 

 

Best Answer
0 Votes

could you please explain how today.getMinutes() % 3 part of the code works?

SN
Best Answer
0 Votes

Sorry, looks like it was slightly wrong. It's using modulo https://stackoverflow.com/questions/16505559/how-can-i-use-modulo-operator-in-javascript

 

That should have been

(today.getMinutes() % 3) === 0

You can see it in action here: https://jsfiddle.net/xz7a0gdf/3/

Best Answer
0 Votes