01-19-2018 13:23 - edited 01-19-2018 13:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-19-2018 13:23 - edited 01-19-2018 13:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

Accepted Solutions
01-20-2018 03:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

SunsetRunner
01-20-2018 03:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

SunsetRunner
01-20-2018 03:23
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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.
