05-06-2019 20:45 - edited 05-07-2019 09:28
05-06-2019 20:45 - edited 05-07-2019 09:28
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()
}
}
Answered! Go to the Best Answer.
Best Answer05-09-2019 03:01
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-09-2019 03:01
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 Answer05-07-2019 10:14 - edited 05-07-2019 10:18
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-07-2019 10:14 - edited 05-07-2019 10:18
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 Answer05-08-2019 18:56
05-08-2019 18:56
could you please explain how today.getMinutes() % 3 part of the code works?
Best Answer05-09-2019 03:01
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
05-09-2019 03:01
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