mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
Grove: Reverted examples and Sources
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
35
examples/javascript/grovebutton.js
Normal file
35
examples/javascript/grovebutton.js
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
|
||||
// Create the button object using GPIO pin 0
|
||||
var button = new groveSensor.GroveButton(0);
|
||||
|
||||
// Read the input and print, waiting one second between readings
|
||||
function readButtonValue() {
|
||||
console.log(button.name() + " value is " + button.value());
|
||||
}
|
||||
setInterval(readButtonValue, 1000);
|
60
examples/javascript/grovecollision.js
Normal file
60
examples/javascript/grovecollision.js
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var collision_lib = require("jsupm_grovecollision");
|
||||
|
||||
// The was tested with the Grove Collision Sensor
|
||||
// Instantiate a Grove Collision on digital pin D2
|
||||
var collision_obj = new collision_lib.GroveCollision(2);
|
||||
|
||||
var collisionState = false;
|
||||
console.log("No collision");
|
||||
|
||||
// Having an infinate loop prevents nodeJS from catching Cntl-C
|
||||
// We need to catch Cntl-C to clean up memory
|
||||
// Instead, we check the collision sensor every millisecond
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
if (collision_obj.isColliding() && !collisionState)
|
||||
{
|
||||
console.log("Collision!");
|
||||
collisionState = true;
|
||||
}
|
||||
else if (!collision_obj.isColliding() && collisionState)
|
||||
{
|
||||
console.log("No collision");
|
||||
collisionState = false;
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// When exiting: clear interval, clean up memory, and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
collision_obj = null;
|
||||
collision_lib.cleanUp();
|
||||
collision_lib = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
62
examples/javascript/groveehr.js
Normal file
62
examples/javascript/groveehr.js
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load heart rate sensor module
|
||||
var heartRateSensor = require('jsupm_groveehr');
|
||||
// Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
|
||||
var myHeartRateSensor = new heartRateSensor.GroveEHR(2);
|
||||
|
||||
// set the beat counter to 0, init the clock and start counting beats
|
||||
myHeartRateSensor.clearBeatCounter();
|
||||
myHeartRateSensor.initClock();
|
||||
myHeartRateSensor.startBeatCounter();
|
||||
|
||||
var millis, beats, hr;
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
// we grab these just for display purposes in this example
|
||||
millis = myHeartRateSensor.getMillis();
|
||||
beats = myHeartRateSensor.beatCounter();
|
||||
|
||||
// heartRate() requires that at least 5 seconds pass before
|
||||
// returning anything other than 0
|
||||
hr = myHeartRateSensor.heartRate();
|
||||
|
||||
// output milliseconds passed, beat count, and computed heart rate
|
||||
console.log("Millis: " + millis + " Beats: " + beats +
|
||||
" Heart Rate: " + hr);
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
myHeartRateSensor.stopBeatCounter();
|
||||
myHeartRateSensor = null
|
||||
heartRateSensor.cleanUp();
|
||||
heartRateSensor = null;
|
||||
|
||||
console.log("Exiting");
|
||||
process.exit(0);
|
||||
});
|
52
examples/javascript/groveeldriver.js
Normal file
52
examples/javascript/groveeldriver.js
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var eldriver_lib = require("jsupm_groveeldriver");
|
||||
|
||||
// The was tested with the Grove El Driver Module
|
||||
// Instantiate a Grove El Driver on digital pin D2
|
||||
var eldriver_obj = new eldriver_lib.GroveElDriver(2);
|
||||
|
||||
var lightState = true;
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
if (lightState)
|
||||
eldriver_obj.on();
|
||||
else
|
||||
eldriver_obj.off();
|
||||
lightState = !lightState;
|
||||
}, 1000);
|
||||
|
||||
// When exiting: turn off EL wire, clear interval, and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
eldriver_obj.off();
|
||||
eldriver_obj = null;
|
||||
eldriver_lib.cleanUp();
|
||||
eldriver_lib = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
55
examples/javascript/groveelectromagnet.js
Normal file
55
examples/javascript/groveelectromagnet.js
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var electromagnet_lib = require("jsupm_groveelectromagnet");
|
||||
// The was tested with the Grove Electromagnetic Module
|
||||
// Instantiate a Grove Electromagnet on digital pin D2
|
||||
var electromagnet_obj = new electromagnet_lib.GroveElectromagnet(2);
|
||||
console.log("Starting up magnet....");
|
||||
electromagnet_obj.off();
|
||||
|
||||
var magnetState = false;
|
||||
|
||||
// Turn magnet on and off every 5 seconds
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
magnetState = !magnetState;
|
||||
if (magnetState)
|
||||
electromagnet_obj.on();
|
||||
else
|
||||
electromagnet_obj.off();
|
||||
console.log("Turning magnet " + ((magnetState) ? "on" : "off"));
|
||||
}, 5000);
|
||||
|
||||
// When exiting: clear interval, turn off magnet, run memory cleanup, and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
electromagnet_obj.off();
|
||||
electromagnet_obj = null;
|
||||
electromagnet_lib.cleanUp();
|
||||
electromagnet_lib = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
46
examples/javascript/groveemg.js
Normal file
46
examples/javascript/groveemg.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
var groveemg_lib = require("jsupm_groveemg");
|
||||
|
||||
// The was tested with the GroveEMG Muscle Signal Reader Sensor Module
|
||||
// Instantiate a GroveEMG on analog pin A0
|
||||
var groveemg_obj = new groveemg_lib.GroveEMG(0);
|
||||
console.log("Calibrating....");
|
||||
groveemg_obj.calibrate();
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
console.log(groveemg_obj.value());
|
||||
}, 100);
|
||||
|
||||
// When exiting: clear interval, and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
groveemg_obj = null;
|
||||
groveemg_lib.cleanUp();
|
||||
groveemg_lib = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
111
examples/javascript/grovegprs.js
Normal file
111
examples/javascript/grovegprs.js
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
var sensorObj = require('jsupm_grovegprs');
|
||||
|
||||
|
||||
/************** Functions **************/
|
||||
function printUsage(progname)
|
||||
{
|
||||
var outputStr = "Usage: " + progname + " [AT command]\n\n" +
|
||||
"If an argument is supplied on the command line, that argument is\n" +
|
||||
"sent to the module and the response is printed out.\n\n" +
|
||||
"If no argument is used, then the manufacturer and the current\n" +
|
||||
"saved profiles are queried and the results printed out.\n\n"
|
||||
console.log(outputStr);
|
||||
}
|
||||
|
||||
// simple helper function to send a command and wait for a response
|
||||
function sendCommand(sensor, cmd, callback)
|
||||
{
|
||||
// commands need to be terminated with a carriage return
|
||||
cmd += "\r";
|
||||
sensor.writeDataStr(cmd);
|
||||
|
||||
// wait up to 1 second
|
||||
if (sensor.dataAvailable(1000))
|
||||
{
|
||||
console.log("Returned: " + sensor.readDataStr(1024));
|
||||
}
|
||||
else
|
||||
console.log("Timed out waiting for response");
|
||||
|
||||
if (callback)
|
||||
callback();
|
||||
}
|
||||
|
||||
/************** Main code **************/
|
||||
// Instantiate a GROVEGPRS Module on UART 0
|
||||
var sensor = new sensorObj.GroveGPRS(0);
|
||||
|
||||
// Set the baud rate, 19200 baud is the default.
|
||||
if (sensor.setBaudRate(19200))
|
||||
{
|
||||
console.log("Failed to set baud rate");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
printUsage(process.argv[1]);
|
||||
|
||||
// Note: in nodeJS, command-line argument 0 is "node".
|
||||
// Command-line argument 1 is "grovegprs.js"
|
||||
// If you have a third argument, then it's a command
|
||||
if (process.argv.length > 2)
|
||||
{
|
||||
console.log("Sending command line argument (" + process.argv[2] + ")...");
|
||||
sendCommand(sensor, process.argv[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// sending this command as a synchronous callback ensures better timing
|
||||
var callbackFunc = function()
|
||||
{
|
||||
setTimeout(function()
|
||||
{
|
||||
// query the saved profiles
|
||||
console.log("Querying the saved profiles (AT&V)...");
|
||||
sendCommand(sensor, "AT&V");
|
||||
|
||||
// A comprehensive list is available from the
|
||||
// datasheet at:
|
||||
// http://www.seeedstudio.com/wiki/images/7/72/AT_Commands_v1.11.pdf
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
// query the module manufacturer
|
||||
console.log("Querying module manufacturer (AT+CGMI)...");
|
||||
sendCommand(sensor, "AT+CGMI", callbackFunc);
|
||||
}
|
||||
|
||||
|
||||
/************** Exit code **************/
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
49
examples/javascript/grovegsr.js
Normal file
49
examples/javascript/grovegsr.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var grovegsr_lib = require("jsupm_grovegsr");
|
||||
|
||||
// The was tested with the GroveGSR Galvanic Skin Response Sensor module.
|
||||
|
||||
// Instantiate a GroveGSR on analog pin A0
|
||||
var grovegsr_obj = new grovegsr_lib.GroveGSR(0);
|
||||
console.log("Calibrating....");
|
||||
grovegsr_obj.calibrate();
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
console.log(grovegsr_obj.value());
|
||||
}, 500);
|
||||
|
||||
|
||||
// When exiting: clear interval, and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
grovegsr_obj = null;
|
||||
grovegsr_lib.cleanUp();
|
||||
grovegsr_lib = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
46
examples/javascript/groveled.js
Normal file
46
examples/javascript/groveled.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
|
||||
// Create the Grove LED object using GPIO pin 2
|
||||
var led = new groveSensor.GroveLed(2);
|
||||
|
||||
// Print the name
|
||||
console.log(led.name());
|
||||
|
||||
// Turn the LED on and off 10 times, pausing one second
|
||||
// between transitions
|
||||
var i = 0;
|
||||
var waiting = setInterval(function() {
|
||||
if ( i % 2 == 0 ) {
|
||||
led.on();
|
||||
} else {
|
||||
led.off();
|
||||
}
|
||||
i++;
|
||||
if ( i == 20 ) clearInterval(waiting);
|
||||
}, 1000);
|
||||
|
37
examples/javascript/grovelight.js
Normal file
37
examples/javascript/grovelight.js
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
|
||||
// Create the light sensor object using AIO pin 0
|
||||
var light = new groveSensor.GroveLight(0);
|
||||
|
||||
// Read the input and print both the raw value and a rough lux value,
|
||||
// waiting one second between readings
|
||||
function readLightSensorValue() {
|
||||
console.log(light.name() + " raw value is " + light.raw_value() +
|
||||
", which is roughly " + light.value() + " lux");
|
||||
}
|
||||
setInterval(readLightSensorValue, 1000);
|
54
examples/javascript/grovemoisture.js
Normal file
54
examples/javascript/grovemoisture.js
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//Load Grove Moisture module
|
||||
var grove_moisture = require('jsupm_grovemoisture');
|
||||
|
||||
// Instantiate a Grove Moisture sensor on analog pin A0
|
||||
var myMoistureObj = new grove_moisture.GroveMoisture(0);
|
||||
|
||||
// Values (approximate):
|
||||
// 0-300, sensor in air or dry soil
|
||||
// 300-600, sensor in humid soil
|
||||
// 600+, sensor in wet soil or submerged in water
|
||||
// Read the value every second and print the corresponding moisture level
|
||||
setInterval(function()
|
||||
{
|
||||
var result;
|
||||
var moisture_val = parseInt(myMoistureObj.value());
|
||||
if (moisture_val >= 0 && moisture_val < 300)
|
||||
result = "Dry";
|
||||
else if (moisture_val >= 300 && moisture_val < 600)
|
||||
result = "Moist";
|
||||
else
|
||||
result = "Wet";
|
||||
console.log("Moisture value: " + moisture_val + ", " + result);
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
50
examples/javascript/groveo2.js
Normal file
50
examples/javascript/groveo2.js
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
var groveO2_lib = require("jsupm_groveo2");
|
||||
|
||||
// The was tested with the O2 Oxygen Concentration Sensor Module
|
||||
// Instantiate a GroveO2 on analog pin A0
|
||||
var groveO2_obj = new groveO2_lib.GroveO2(0);
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
console.log("The output voltage is: " + roundNum(groveO2_obj.voltageValue(), 5) + "mV");
|
||||
}, 100);
|
||||
|
||||
function roundNum(num, decimalPlaces)
|
||||
{
|
||||
var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
|
||||
return (Math.round((num + extraNum) * (Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces));
|
||||
}
|
||||
|
||||
// When exiting: clear interval, and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
groveO2_obj = null;
|
||||
groveO2_lib.cleanUp();
|
||||
groveO2_lib = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
49
examples/javascript/groverelay.js
Normal file
49
examples/javascript/groverelay.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
|
||||
// Create the relay switch object using GPIO pin 0
|
||||
var relay = new groveSensor.GroveRelay(0);
|
||||
|
||||
// Close and then open the relay switch 3 times,
|
||||
// waiting one second each time. The LED on the relay switch
|
||||
// will light up when the switch is on (closed).
|
||||
// The switch will also make a noise between transitions.
|
||||
var i = 0;
|
||||
var waiting = setInterval(function() {
|
||||
if ( i % 2 == 0 ) {
|
||||
relay.on();
|
||||
if ( relay.isOn() )
|
||||
console.log(relay.name() + " is on");
|
||||
} else {
|
||||
relay.off();
|
||||
if ( relay.isOff() )
|
||||
console.log(relay.name() + " is off");
|
||||
}
|
||||
i++;
|
||||
if ( i == 6) clearInterval(waiting);
|
||||
}, 1000);
|
||||
|
49
examples/javascript/groverotary.js
Normal file
49
examples/javascript/groverotary.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//setup/Initialization
|
||||
var upm_grove = require('jsupm_grove');
|
||||
|
||||
//setup access analog input Analog pin #0 (A0)
|
||||
var groveRotary = new upm_grove.GroveRotary(0);
|
||||
|
||||
loop();
|
||||
|
||||
function loop()
|
||||
{
|
||||
var abs = groveRotary.abs_value();
|
||||
var absdeg = groveRotary.abs_deg();
|
||||
var absrad = groveRotary.abs_rad();
|
||||
|
||||
var rel = groveRotary.rel_value();
|
||||
var reldeg = groveRotary.rel_deg();
|
||||
var relrad = groveRotary.rel_rad();
|
||||
|
||||
//write the knob value to the console in different formats
|
||||
console.log("Abs: " + abs + " " + Math.round(parseInt(absdeg)) + " " + absrad.toFixed(3));
|
||||
console.log("Rel: " + rel + " " + Math.round(parseInt(reldeg)) + " " + relrad.toFixed(3));
|
||||
|
||||
//wait 2 s and call function again
|
||||
setTimeout(loop, 2000);
|
||||
}
|
42
examples/javascript/groveslide.js
Normal file
42
examples/javascript/groveslide.js
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var upm_grove = require('jsupm_grove');
|
||||
|
||||
//setup access analog input Analog pin #0 (A0)
|
||||
var groveSlide = new upm_grove.GroveSlide(0);
|
||||
|
||||
loop();
|
||||
|
||||
function loop()
|
||||
{
|
||||
var raw = groveSlide.raw_value();
|
||||
var volts = groveSlide.voltage_value();
|
||||
|
||||
//write the slider values to the console
|
||||
console.log("Slider Value: " + raw + " = " + volts.toFixed(2) + " V");
|
||||
|
||||
//wait 2 s then call function again
|
||||
setTimeout(loop, 2000);
|
||||
}
|
41
examples/javascript/grovespeaker.js
Normal file
41
examples/javascript/grovespeaker.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//Load Grove Speaker module
|
||||
var groveSpeaker = require('jsupm_grovespeaker');
|
||||
// Instantiate a Grove Speaker on digital pin D2
|
||||
var mySpeaker = new groveSpeaker.GroveSpeaker(2);
|
||||
|
||||
// Play all 7 of the lowest notes
|
||||
mySpeaker.playAll();
|
||||
|
||||
// Play a medium C-sharp
|
||||
mySpeaker.playSound('c', true, "med");
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
42
examples/javascript/grovetemp.js
Normal file
42
examples/javascript/grovetemp.js
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
|
||||
// Create the temperature sensor object using AIO pin 0
|
||||
var temp = new groveSensor.GroveTemp(0);
|
||||
console.log(temp.name());
|
||||
|
||||
// Read the temperature ten times, printing both the Celsius and
|
||||
// equivalent Fahrenheit temperature, waiting one second between readings
|
||||
var i = 0;
|
||||
var waiting = setInterval(function() {
|
||||
var celsius = temp.value();
|
||||
var fahrenheit = celsius * 9.0/5.0 + 32.0;
|
||||
console.log(celsius + " degrees Celsius, or " +
|
||||
Math.round(fahrenheit) + " degrees Fahrenheit");
|
||||
i++;
|
||||
if (i == 10) clearInterval(waiting);
|
||||
}, 1000);
|
51
examples/javascript/grovevdiv.js
Normal file
51
examples/javascript/grovevdiv.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var voltageDivider = require('jsupm_grovevdiv');
|
||||
// Instantiate a Grove Voltage Divider sensor on analog pin A0
|
||||
var myVoltageDivider = new voltageDivider.GroveVDiv(0);
|
||||
|
||||
// collect data and output measured voltage according to the setting
|
||||
// of the scaling switch (3 or 10)
|
||||
var val, gain3val, gain10val;
|
||||
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");
|
||||
}
|
||||
|
||||
setInterval(getVoltageInfo, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
myVoltageDivider = null;
|
||||
voltageDivider.cleanUp();
|
||||
voltageDivider = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
46
examples/javascript/grovewater.js
Normal file
46
examples/javascript/grovewater.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var waterSensor = require('jsupm_grovewater');
|
||||
|
||||
// Instantiate a Grove Water sensor on digital pin D2
|
||||
var water = new waterSensor.GroveWater(2);
|
||||
|
||||
// Read whether the sensor is wet/dry, waiting one second between readings
|
||||
function readWaterState()
|
||||
{
|
||||
if (water.isWet())
|
||||
console.log("Sensor is wet");
|
||||
else
|
||||
console.log("Sensor is dry");
|
||||
}
|
||||
setInterval(readWaterState, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
Reference in New Issue
Block a user