upm/examples/javascript/bh1749.js
Mihai Tudor Panu 89d5de43e0 license: update to SPDX style license text throughout
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2020-03-05 15:13:36 -08:00

47 lines
1.1 KiB
JavaScript
Executable File

/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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.
*
* SPDX-License-Identifier: MIT
*/
var bh1749 = require("jsupm_bh1749");
var bh1749_sensor = new bh1749.BH1749();
bh1749_sensor.SensorInit(
bh1749.INT_JUDGE_1,
bh1749.MEAS_240MS,
bh1749.RGB_GAIN_1X,
bh1749.IR_GAIN_1X,
bh1749.RED);
bh1749_sensor.SetThresholdHigh(511);
bh1749_sensor.Enable();
var waitTime = bh1749_sensor.GetMeasurementTime();
var counter = 10;
console.log("Color readings: ");
var interval = setInterval(function() {
data = bh1749_sensor.GetMeasurements();
console.log(
"R: " + data.get(0) + ", G: " + data.get(1) + ", B: " + data.get(2) +
", IR: " + data.get(3) + ", G2: " + data.get(4)
);
counter--;
if (counter == 0) {
clearInterval(interval);
}
}, waitTime);
process.on("SIGINT", function() {
clearInterval(interval);
console.log("Exiting...");
process.exit(0);
});