Skip to content

augustskare/heart-rate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

<heart-rate></heart-rate>

Web component that displays heart rate from a Bluetooth connected heart rate monitor.

📡 Demo 📡

Usage

Import and insert the element in your document:

<html>
  <head>
    <link rel="import" href="heart-rate/heart-rate.html">
  </head>
  <body>
    <heart-rate></heart-rate>
  </body>
</html>

Discovering Bluetooth devices must be triggered by a user gesture. Use the .connect() function to connect to the heart rate monitor, this returns a promise.

document.querySelector('button').addEventListener('click', event => {
  document.querySelector('heart-rate').connect().then(device => {
    // connected
  });
});

Listen for heart rate change:

document.querySelector('heart-rate').addEventListener('change', event => {
  const value = event.target.value;
  console.log(value);
});