Skip to content

Commit

Permalink
Merge pull request #25 from chirimen-oh/Grove-Accelerometer-(adxl345)
Browse files Browse the repository at this point in the history
Grove Acceloerometer Node.js exampleの作成と読み込むドライバをES module化したものに変更
  • Loading branch information
kou029w authored Jan 30, 2020
2 parents 1348971 + a8cfc7e commit 661b77a
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 723 deletions.
5 changes: 2 additions & 3 deletions examples/adxl345/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
content="width=device-width, user-scalable=no, initial-scale=1"
/>
<title>Grove Digital Accelerometer sensor</title>
<script src="node_modules/@chirimen-raspi/polyfill/polyfill.js"></script>
<script src="node_modules/@chirimen-raspi/chirimen-driver-i2c-grove-accelerometer/GROVEACCELEROMETER.js"></script>
<script src="./main.js" defer></script>
<script src="https://r.chirimen.org/polyfill.js"></script>
<script src="./main.js" type="module"></script>
<style>
p {
color: blue;
Expand Down
18 changes: 10 additions & 8 deletions examples/adxl345/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import GROVEACCELEROMETER from "https://unpkg.com/@chirimen/grove-accelerometer?module";

main();

async function main() {
var ax = document.getElementById("ax");
var ay = document.getElementById("ay");
var az = document.getElementById("az");
var i2cAccess = await navigator.requestI2CAccess();
var port = i2cAccess.ports.get(1);
var groveaccelerometer = new GROVEACCELEROMETER(port, 0x53);
const ax = document.getElementById("ax");
const ay = document.getElementById("ay");
const az = document.getElementById("az");
const i2cAccess = await navigator.requestI2CAccess();
const port = i2cAccess.ports.get(1);
const groveaccelerometer = new GROVEACCELEROMETER(port, 0x53);
await groveaccelerometer.init();
for (;;) {
try {
var values = await groveaccelerometer.read();
const values = await groveaccelerometer.read();
ax.innerHTML = values.x ? values.x : ax.innerHTML;
ay.innerHTML = values.y ? values.y : ay.innerHTML;
az.innerHTML = values.z ? values.z : az.innerHTML;
} catch (err) {
console.log("READ ERROR:" + err);
console.error("READ ERROR:" + err);
}
await sleep(1000);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 661b77a

Please sign in to comment.