2019-10-18 21:41:11 +09:00
|
|
|
# node-web-i2c
|
2019-10-18 03:23:29 +09:00
|
|
|
|
|
|
|
I2C access with Node.js
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
2019-10-18 21:41:11 +09:00
|
|
|
const { requestI2CAccess } = require("node-web-i2c");
|
2019-10-28 01:10:25 +09:00
|
|
|
const ADT7410 = require("@chirimen/adt7410");
|
2019-10-18 03:23:29 +09:00
|
|
|
|
|
|
|
const ADT7410_ADDR = 0x48;
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const i2cAccess = await requestI2CAccess();
|
2019-10-18 10:27:56 +09:00
|
|
|
const port = i2cAccess.ports.get(1);
|
2019-10-28 01:10:25 +09:00
|
|
|
const adt7410 = new ADT7410(port, ADT7410_ADDR);
|
|
|
|
await adt7410.init();
|
|
|
|
const temperature = await adt7410.read();
|
2019-10-18 03:23:29 +09:00
|
|
|
console.log(`Temperature: ${temperature} ℃`);
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|
|
|
|
```
|
|
|
|
|
|
|
|
## Document
|
|
|
|
|
2023-02-17 16:01:14 +09:00
|
|
|
- [TSDoc](http://chirimen.org/node-web-i2c/)
|
|
|
|
|
|
|
|
## Reference
|
|
|
|
|
|
|
|
- [Web I2C API for W3C Draft](http://browserobo.github.io/WebI2C)
|