Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grove Acceloerometer Node.js exampleの作成と読み込むドライバをES module化したものに変更 #25

Merged
merged 2 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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