forked from NordicPlayground/Nordic-Thingy52-Thingyjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
38 lines (36 loc) · 983 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!doctype html>
<html>
<head>
<title>Thingy:52 Web Bluetooth</title>
</head>
<body>
<button id="connectBtn">Connect</button>
<div id="microphone"></div>
<script type="module">
import Thingy from "./index.js";
const thingy = new Thingy({logEnabled: true});
const myLogger = data => {
const tempData = data.detail;
console.log(tempData);
}
async function start(device) {
try {
await device.connect();
device.addEventListener("temperature", myLogger);
await device.temperature.start();
await device.led.write({
mode: "breathe",
color: "red",
intensity: 50,
delay: 1000,
});
} catch (error) {
console.error(error);
}
}
document.querySelector("#connectBtn").addEventListener("click", async () => {
start(thingy);
});
</script>
</body>
</html>