Skip to content

Instantly share code, notes, and snippets.

@w4ilun
Created September 30, 2016 20:47
Show Gist options
  • Save w4ilun/e2fa62c8e5289e7a8a0c652fd89c06d2 to your computer and use it in GitHub Desktop.
Save w4ilun/e2fa62c8e5289e7a8a0c652fd89c06d2 to your computer and use it in GitHub Desktop.
var mraa = require('mraa');
var version = mraa.getVersion();
if (version >= 'v0.6.1') {
console.log('mraa version (' + version + ') ok');
}
else {
console.log('mraa version(' + version + ') is old - this code may not work')
}
var ads1115 = new mraa.I2c(0);
ads1115.address(0x48)
setInterval(function(){
//A0
ads1115.writeWordReg(1, 0x83C1);
//A1
// ads1115.writeWordReg(1, 0x83D1);
//A2
// ads1115.writeWordReg(1, 0x83E1);
//A3
// ads1115.writeWordReg(1, 0x83F1);
var raw = ads1115.readWordReg(0);
var analogValue = ((raw&0xff00)>>8)+((raw&0x00ff)<<8);
console.log(analogValue);
}, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment