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

Confused: Order of Event/Functions

If the OnKeyPress event (function) is before the hrm event, the hrm output fails.

If I turn the order around, the hrm event will work but the OnKeypress event fails.

Only by switching the order in the code (It doesn't matter what happens within the functions).

 

document.onkeypress = function(e) {
  switch(e.key)
    {
      case "up":      
        (config) ?  setServe(sides.SIDE_A) : setScore(sides.SIDE_A);
        break;
      case "down":
        (config) ?  setServe(sides.SIDE_B) : setScore(sides.SIDE_B);
        break;
      case "back":
        hrm.stop();
        break;
    }
  (debugLevel >= levels.LOW) && console.log(e.Key);
}


var hrm = new HeartRateSensor();
var txtHeartRate = document.getElementById("heartrate");
hrm.onreading = function() {
  txtHeartRate.innerText = hrm.heartRate;
  (debugLevel >= levels.HIGH) && console.log(hrm.heartRate);
  hrm.stop();
}
Best Answer
0 Votes
4 REPLIES 4

Put these two lines above both events.

 

var hrm = new HeartRateSensor();
var txtHeartRate = document.getElementById("heartrate");
Best Answer
0 Votes

Same Problem 😞

Best Answer
0 Votes

Doesn't anyone have an idea?

Best Answer
0 Votes

Can you put the project on Github? Thanks

Best Answer
0 Votes