npm i
node index.js
Last active
November 3, 2019 01:19
-
-
Save kou029w/ac7cc2ea8e64095a4d97cf6e379cca54 to your computer and use it in GitHub Desktop.
ads1x15 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
global.sleep = sleep; | |
const {requestI2CAccess} = require("node-web-i2c"); | |
const ADS1115 = require("@chirimen/ads1x15"); | |
const ads1115Addr = 0x48; | |
async function main() { | |
const i2cAccess = await requestI2CAccess(); | |
const port = i2cAccess.ports.get(1); | |
const ads1115 = new ADS1115(port, ads1115Addr); | |
await ads1115.init(true); | |
let value = ads1115.getVoltage(await ads1115.read(0)); | |
console.log(`Value0: ${value}`); | |
value = ads1115.getVoltage(await ads1115.read(1)); | |
console.log(`Value1: ${value}`); | |
value = ads1115.getVoltage(await ads1115.read(2)); | |
console.log(`Value2: ${value}`); | |
value = ads1115.getVoltage(await ads1115.read(3)); | |
console.log(`Value3: ${value}`); | |
} | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "i2c-ads1015-example", | |
"version": "1.0.0", | |
"private": true, | |
"dependencies": { | |
"@chirimen/ads1x15": "^1.0.0-alpha.0", | |
"node-web-i2c": "^1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment