2014-12-19 15:17:36 -07:00
|
|
|
/*
|
2016-11-03 10:55:07 +08:00
|
|
|
* Author: Zion Orent <zorent@ics.com>
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2016-11-03 10:55:07 +08:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-11-03 10:55:07 +08:00
|
|
|
*/
|
2014-12-19 15:17:36 -07:00
|
|
|
|
2016-09-01 16:32:49 -07:00
|
|
|
var voltageDivider = require('jsupm_vdiv');
|
2016-11-03 10:55:07 +08:00
|
|
|
// Instantiate a Voltage Divider sensor on analog pin A0
|
2016-09-01 16:32:49 -07:00
|
|
|
var myVoltageDivider = new voltageDivider.VDiv(0);
|
2014-12-19 15:17:36 -07:00
|
|
|
|
|
|
|
// collect data and output measured voltage according to the setting
|
|
|
|
// of the scaling switch (3 or 10)
|
2015-03-26 09:58:41 -04:00
|
|
|
var val, gain3val, gain10val;
|
2016-11-03 10:55:07 +08:00
|
|
|
|
|
|
|
function getVoltageInfo() {
|
|
|
|
val = myVoltageDivider.value(100);
|
|
|
|
gain3val = myVoltageDivider.computedValue(3, val);
|
|
|
|
gain10val = myVoltageDivider.computedValue(10, val);
|
|
|
|
console.log("ADC value: " + val + " Gain 3: " + gain3val + "v Gain 10: " + gain10val + "v");
|
2014-12-19 15:17:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(getVoltageInfo, 1000);
|
|
|
|
|
|
|
|
// Print message when exiting
|
2016-11-03 10:55:07 +08:00
|
|
|
process.on('SIGINT', function() {
|
|
|
|
myVoltageDivider = null;
|
|
|
|
voltageDivider.cleanUp();
|
|
|
|
voltageDivider = null;
|
|
|
|
console.log("Exiting...");
|
|
|
|
process.exit(0);
|
2014-12-19 15:17:36 -07:00
|
|
|
});
|