01-19-2018 13:23 - edited 01-19-2018 13:24
01-19-2018 13:23 - edited 01-19-2018 13:24
I am working on a watchface and have the heart rate loading and displaying with the following code:
hrm.start();
var hrm = new HeartRateSensor();
hrm.onreading = function () {
let hr = (hrm.heartRate);
let myHR = document.getElementById("myHR");
myHR.text = (hr);
hrm.stop();
}
Am I missing something simple? Maybe setting an interval?
I thought I could write a fuction to update the HR called updateHR with the above code:
//function updateHR() {
let hrm = new HeartRateSensor();
hrm.start();
let hr = (hrm.heartRate);
let myHR = document.getElementById("myHR");
myHR.text = (hr);
hrm.stop();
But when I run it, all of my text fields disappear. Here is my code for the onchange:
display.onchange = function() {
if (display.on) {
updateHR();
}
}
Answered! Go to the Best Answer.
01-20-2018 03:23
01-20-2018 03:23
The hrm.onreading will call the function on each reading taken. Problem is you have hrm.stop() in the function so will only call once.
Move hrm.stop() into a document.onunload event instead.
01-20-2018 03:23
01-20-2018 03:23
The hrm.onreading will call the function on each reading taken. Problem is you have hrm.stop() in the function so will only call once.
Move hrm.stop() into a document.onunload event instead.