-
Notifications
You must be signed in to change notification settings - Fork 4
/
microbit-web-bluetooth-magnetometer.html
59 lines (59 loc) · 2.67 KB
/
microbit-web-bluetooth-magnetometer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title>Web Bluetooth micro:bit Magnetometer</title>
<h1>Web Bluetooth micro:bit Magnetometer</h1>
<p>Scan Bluetooth devices (using "BBC micro:bit" as namePrefix filter). Allows to interact with the micro:bit using the Bluetooth Magnetometer service.<br>Example MakeCode micro:bit project <a href="https://makecode.microbit.org/_VL8YPJcEX1V7" target="_blank">here</a> (or <a href="https://makecode.microbit.org/#pub:_VL8YPJcEX1V7" target="_blank">here</a> to open in MakeCode directly).</p>
</head>
<body id="body" style="background-color:#FFD0D0">
<button onclick="connect()">Connect</button>
<button onclick="disconnect()">Disconnect</button>
<h2>Magnetometer Data (μT)</h2>
<table>
<tr>
<td>x:</td>
<td id="magnetometerX">-</td>
</tr>
<tr>
<td>y:</td>
<td id="magnetometerY">-</td>
</tr>
<tr>
<td>z:</td>
<td id="magnetometerZ">-</td>
</tr>
</table>
<h2>Magnetometer Period (ms)</h2>
<input type="text" id="magnetometerPeriodText" disabled="true">
<button onclick="readMagnetometerPeriod()">Read</button>
<br>
<select id="magnetometerPeriodSelect">
<option value="12">12</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="400">400</option>
<option value="800">800</option>
<option value="1600">1600</option>
<option value="3200">3200</option>
<option value="6400">6400</option>
<option value="12800">12800</option>
</select>
<button onclick="writeMagnetometerPeriod()">Write</button>
<h2>Magnetometer Bearing (° from north)</h2>
<p id="bearing">-</p>
<h2>Magnetometer Calibration</h2>
<p id="calibration">-</p>
<select id="magnetometerCalibrationSelect">
<option value="0">State unknown</option>
<option value="1">Calibration requested</option>
<option value="2">Calibration completed OK</option>
<option value="3">Calibration completed with error</option>
</select>
<button onclick="writeMagnetometerCalibration()">Write</button>
<h2>Log <button onclick="clearLog()">Clear</button></h2>
<p id="log" style="font-family:'Courier New',Courier,monospace"></p>
</body>
<script src="microbit-web-bluetooth-magnetometer.js"></script>
</html>