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

VL53L1X exampleを作成 #44

Merged
merged 5 commits into from
Feb 6, 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
35 changes: 35 additions & 0 deletions examples/vl53l1x/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1"
/>
<title>i2c-VL53L1X</title>
<script src="https://r.chirimen.org/polyfill.js"></script>
<script src="./main.js" type="module"></script>
<style>
p {
color: blue;
text-align: center;
font-size: 24px;
}

img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>

<body>
<p>
<a>VL53L1X</a>
</p>
<img src="./schematic.png" height="400px" />
<p id="value">initializing...</p>
</body>
</html>
23 changes: 23 additions & 0 deletions examples/vl53l1x/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import VL53L1X from "https://unpkg.com/@chirimen/vl53l1x?module";

main();

async function main() {
const value = document.getElementById("value");
const i2cAccess = await navigator.requestI2CAccess();
const port = i2cAccess.ports.get(1);
const vl53l1x = new VL53L1X(port, 0x29);

// Mode: short, medium, long
await vl53l1x.init("short");

// Necessary to start measurement
await vl53l1x.startContinuous();

while (true) {
const distance = await vl53l1x.read();
value.innerHTML = data.toFixed(2) + " mm";

await sleep(500);
}
}
5 changes: 5 additions & 0 deletions examples/vl53l1x/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "i2c-vl53l1x-example",
"version": "1.0.0",
"private": true
}
3 changes: 3 additions & 0 deletions examples/vl53l1x/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"template": "static"
}
Binary file added examples/vl53l1x/schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions node-examples/vl53l1x/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { requestI2CAccess } = require("node-web-i2c");
const VL53L1X = require("@chirimen/vl53l1x");
const { promisify } = require("util");
const sleep = promisify(setTimeout);

main();

async function main() {
const i2cAccess = await requestI2CAccess();
const port = i2cAccess.ports.get(1);
const vl53l1x = new VL53L1X(port, 0x29);

// Mode: short, medium, long
await vl53l1x.init("short");

// Necessary to start measurement
await vl53l1x.startContinuous();

while (true) {
const distance = await vl53l1x.read();
console.log(distance.toFixed(2) + " mm");
await sleep(500);
}
}
9 changes: 9 additions & 0 deletions node-examples/vl53l1x/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "i2c-vl53l1x-node-example",
"version": "1.0.0",
"private": true,
"dependencies": {
"@chirimen/vl53l1x": "latest",
"node-web-i2c": "latest"
}
}
5 changes: 5 additions & 0 deletions node-examples/vl53l1x/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# VL53L1X レーザー距離センサー

## 配線図

![配線図](./schematic.png "schematic")
Binary file added node-examples/vl53l1x/schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.