2014-12-10 11:16:32 -07: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.
|
2014-12-10 11:16:32 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-10 11:16:32 -07:00
|
|
|
*/
|
|
|
|
|
2016-11-03 10:55:07 +08:00
|
|
|
// Load UPM module
|
2016-09-13 15:03:26 -07:00
|
|
|
var waterSensor = require('jsupm_water');
|
2014-12-10 11:16:32 -07:00
|
|
|
|
2016-09-13 15:03:26 -07:00
|
|
|
// Instantiate a Water sensor on digital pin D2
|
|
|
|
var water = new waterSensor.Water(2);
|
2014-12-10 11:16:32 -07:00
|
|
|
|
|
|
|
// Read whether the sensor is wet/dry, waiting one second between readings
|
2016-11-03 10:55:07 +08:00
|
|
|
function readWaterState() {
|
|
|
|
if (water.isWet())
|
|
|
|
console.log("Sensor is wet");
|
|
|
|
else
|
|
|
|
console.log("Sensor is dry");
|
2014-12-10 11:16:32 -07:00
|
|
|
}
|
|
|
|
setInterval(readWaterState, 1000);
|
|
|
|
|
|
|
|
// Print message when exiting
|
2016-11-03 10:55:07 +08:00
|
|
|
process.on('SIGINT', function() {
|
|
|
|
console.log("Exiting...");
|
|
|
|
process.exit(0);
|
2014-12-10 11:16:32 -07:00
|
|
|
});
|