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

Update HR with display.onchange

ANSWERED

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();

  }
}

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
1 REPLY 1

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.

Best Answer