mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
Grove: Reverted examples and Sources
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
4d39f1ee84
commit
ea4b1b6aa7
@ -88,12 +88,19 @@ link_directories (${MRAA_LIBDIR})
|
|||||||
# grove* will use module grove
|
# grove* will use module grove
|
||||||
add_example (hmc5883l)
|
add_example (hmc5883l)
|
||||||
add_example (led)
|
add_example (led)
|
||||||
|
add_example (groveled)
|
||||||
add_example (relay)
|
add_example (relay)
|
||||||
|
add_example (groverelay)
|
||||||
add_example (light)
|
add_example (light)
|
||||||
|
add_example (grovelight)
|
||||||
add_example (temperature)
|
add_example (temperature)
|
||||||
|
add_example (grovetemp)
|
||||||
add_example (button)
|
add_example (button)
|
||||||
|
add_example (grovebutton)
|
||||||
add_example (rotary)
|
add_example (rotary)
|
||||||
|
add_example (groverotary)
|
||||||
add_example (slide)
|
add_example (slide)
|
||||||
|
add_example (groveslide)
|
||||||
add_example (buzzer-sound)
|
add_example (buzzer-sound)
|
||||||
add_example (nrf24l01-transmitter)
|
add_example (nrf24l01-transmitter)
|
||||||
add_example (nrf24l01-receiver)
|
add_example (nrf24l01-receiver)
|
||||||
@ -143,11 +150,15 @@ add_example (ds1307)
|
|||||||
add_example (a110x)
|
add_example (a110x)
|
||||||
add_example (gp2y0a)
|
add_example (gp2y0a)
|
||||||
add_example (moisture)
|
add_example (moisture)
|
||||||
|
add_example (grovemoisture)
|
||||||
add_example (ehr)
|
add_example (ehr)
|
||||||
|
add_example (groveehr)
|
||||||
add_example (ta12200)
|
add_example (ta12200)
|
||||||
add_example (grovelinefinder)
|
add_example (grovelinefinder)
|
||||||
add_example (vdiv)
|
add_example (vdiv)
|
||||||
|
add_example (grovevdiv)
|
||||||
add_example (water)
|
add_example (water)
|
||||||
|
add_example (grovewater)
|
||||||
add_example (guvas12d)
|
add_example (guvas12d)
|
||||||
add_example (mpr121)
|
add_example (mpr121)
|
||||||
add_example (yg1006)
|
add_example (yg1006)
|
||||||
@ -155,6 +166,7 @@ add_example (wt5001)
|
|||||||
add_example (ppd42ns)
|
add_example (ppd42ns)
|
||||||
add_example (mq303a)
|
add_example (mq303a)
|
||||||
add_example (speaker)
|
add_example (speaker)
|
||||||
|
add_example (grovespeaker)
|
||||||
add_example (rfr359f)
|
add_example (rfr359f)
|
||||||
add_example (biss0001)
|
add_example (biss0001)
|
||||||
add_example (rotaryencoder)
|
add_example (rotaryencoder)
|
||||||
@ -168,10 +180,15 @@ add_example (hmtrp)
|
|||||||
add_example (nunchuck)
|
add_example (nunchuck)
|
||||||
add_example (otp538u)
|
add_example (otp538u)
|
||||||
add_example (collision)
|
add_example (collision)
|
||||||
|
add_example (grovecollision)
|
||||||
add_example (electromagnet)
|
add_example (electromagnet)
|
||||||
|
add_example (groveelectromagnet)
|
||||||
add_example (emg)
|
add_example (emg)
|
||||||
|
add_example (groveemg)
|
||||||
add_example (o2)
|
add_example (o2)
|
||||||
|
add_example (groveo2)
|
||||||
add_example (gsr)
|
add_example (gsr)
|
||||||
|
add_example (grovegsr)
|
||||||
add_example (ina132)
|
add_example (ina132)
|
||||||
add_example (l298)
|
add_example (l298)
|
||||||
add_example (l298-stepper)
|
add_example (l298-stepper)
|
||||||
@ -180,6 +197,7 @@ add_example (grovemd)
|
|||||||
add_example (grovemd-stepper)
|
add_example (grovemd-stepper)
|
||||||
add_example (pca9685)
|
add_example (pca9685)
|
||||||
add_example (eldriver)
|
add_example (eldriver)
|
||||||
|
add_example (groveeldriver)
|
||||||
add_example (adafruitss)
|
add_example (adafruitss)
|
||||||
add_example (adafruitms1438)
|
add_example (adafruitms1438)
|
||||||
add_example (adafruitms1438-stepper)
|
add_example (adafruitms1438-stepper)
|
||||||
@ -215,6 +233,7 @@ add_example (mg811)
|
|||||||
add_example (wheelencoder)
|
add_example (wheelencoder)
|
||||||
add_example (sm130)
|
add_example (sm130)
|
||||||
add_example (gprs)
|
add_example (gprs)
|
||||||
|
add_example (grovegprs)
|
||||||
add_example (lm35)
|
add_example (lm35)
|
||||||
add_example (micsv89)
|
add_example (micsv89)
|
||||||
add_example (xbee)
|
add_example (xbee)
|
||||||
|
49
examples/c++/grovebutton.cxx
Normal file
49
examples/c++/grovebutton.cxx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// This example uses GPIO 0
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Create the button object using GPIO pin 0
|
||||||
|
upm::GroveButton* button = new upm::GroveButton(0);
|
||||||
|
|
||||||
|
// Read the input and print, waiting one second between readings
|
||||||
|
while( 1 ) {
|
||||||
|
std::cout << button->name() << " value is " << button->value() << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the button object
|
||||||
|
delete button;
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
69
examples/c++/grovecollision.cxx
Normal file
69
examples/c++/grovecollision.cxx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grovecollision.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with the Grove Collision Sensor
|
||||||
|
// Instantiate a Grove Collision on digital pin D2
|
||||||
|
upm::GroveCollision* collision = new upm::GroveCollision(2);
|
||||||
|
|
||||||
|
bool collisionState = false;
|
||||||
|
cout << "No collision" << endl;
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
if (collision->isColliding() && !collisionState)
|
||||||
|
{
|
||||||
|
cout << "Collision!" << endl;
|
||||||
|
collisionState = true;
|
||||||
|
}
|
||||||
|
else if (collisionState)
|
||||||
|
{
|
||||||
|
cout << "No collision" << endl;
|
||||||
|
collisionState = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
delete collision;
|
||||||
|
return 0;
|
||||||
|
}
|
78
examples/c++/groveehr.cxx
Normal file
78
examples/c++/groveehr.cxx
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "groveehr.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
|
||||||
|
upm::GroveEHR* heart = new upm::GroveEHR(2);
|
||||||
|
|
||||||
|
// set the beat counter to 0, init the clock and start counting beats
|
||||||
|
heart->clearBeatCounter();
|
||||||
|
heart->initClock();
|
||||||
|
heart->startBeatCounter();
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// we grab these just for display purposes in this example
|
||||||
|
uint32_t millis = heart->getMillis();
|
||||||
|
uint32_t beats = heart->beatCounter();
|
||||||
|
|
||||||
|
// heartRate() requires that at least 5 seconds pass before
|
||||||
|
// returning anything other than 0
|
||||||
|
int hr = heart->heartRate();
|
||||||
|
|
||||||
|
// output milliseconds passed, beat count, and computed heart rate
|
||||||
|
cout << "Millis: " << millis << " Beats: " << beats;
|
||||||
|
cout << " Heart Rate: " << hr << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
heart->stopBeatCounter();
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete heart;
|
||||||
|
return 0;
|
||||||
|
}
|
66
examples/c++/groveeldriver.cxx
Normal file
66
examples/c++/groveeldriver.cxx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "groveeldriver.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with the Grove El Driver Module
|
||||||
|
// Instantiate a Grove El Driver on digital pin D2
|
||||||
|
upm::GroveElDriver* eldriver = new upm::GroveElDriver(2);
|
||||||
|
|
||||||
|
bool lightState = true;
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
if (lightState)
|
||||||
|
eldriver->on();
|
||||||
|
else
|
||||||
|
eldriver->off();
|
||||||
|
lightState = !lightState;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
eldriver->off();
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
delete eldriver;
|
||||||
|
return 0;
|
||||||
|
}
|
79
examples/c++/groveelectromagnet.cxx
Normal file
79
examples/c++/groveelectromagnet.cxx
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <time.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "groveelectromagnet.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float get_time()
|
||||||
|
{
|
||||||
|
return ((float)(clock()))/CLOCKS_PER_SEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with the Grove Electromagnetic Module
|
||||||
|
// Instantiate a Grove Electromagnet on digital pin D2
|
||||||
|
upm::GroveElectromagnet* magnet = new upm::GroveElectromagnet(2);
|
||||||
|
cout << "Starting up magnet...." << endl;
|
||||||
|
magnet->off();
|
||||||
|
|
||||||
|
bool magnetState = false;
|
||||||
|
float time_passed = get_time();
|
||||||
|
|
||||||
|
// Turn magnet on and off every 5 seconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
if ((get_time() - time_passed) > 5.0)
|
||||||
|
{
|
||||||
|
magnetState = !magnetState;
|
||||||
|
if (magnetState)
|
||||||
|
magnet->on();
|
||||||
|
else
|
||||||
|
magnet->off();
|
||||||
|
cout << "Turning magnet " << ((magnetState) ? "on" : "off") << endl;
|
||||||
|
time_passed = get_time();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
magnet->off();
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
delete magnet;
|
||||||
|
return 0;
|
||||||
|
}
|
60
examples/c++/groveemg.cxx
Normal file
60
examples/c++/groveemg.cxx
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.
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "groveemg.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with the GroveEMG Muscle Signal Reader Sensor Module
|
||||||
|
// Instantiate a GroveEMG on analog pin A0
|
||||||
|
upm::GroveEMG *emg = new upm::GroveEMG(0);
|
||||||
|
cout << "Calibrating...." << endl;
|
||||||
|
emg->calibrate();
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
cout << emg->value() << endl;
|
||||||
|
usleep(100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
delete emg;
|
||||||
|
return 0;
|
||||||
|
}
|
111
examples/c++/grovegprs.cxx
Normal file
111
examples/c++/grovegprs.cxx
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "grovegprs.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
void printUsage(char *progname)
|
||||||
|
{
|
||||||
|
cout << "Usage: " << progname << " [AT command]" << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
cout << "If an argument is supplied on the command line, that argument is"
|
||||||
|
<< endl;
|
||||||
|
cout << "sent to the module and the response is printed out." << endl;
|
||||||
|
cout << endl;
|
||||||
|
cout << "If no argument is used, then the manufacturer and the current"
|
||||||
|
<< endl;
|
||||||
|
cout << "saved profiles are queried and the results printed out." << endl;
|
||||||
|
cout << endl;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// simple helper function to send a command and wait for a response
|
||||||
|
void sendCommand(upm::GroveGPRS* sensor, string cmd)
|
||||||
|
{
|
||||||
|
// commands need to be terminated with a carriage return
|
||||||
|
cmd += "\r";
|
||||||
|
|
||||||
|
sensor->writeDataStr(cmd);
|
||||||
|
|
||||||
|
// wait up to 1 second
|
||||||
|
if (sensor->dataAvailable(1000))
|
||||||
|
{
|
||||||
|
cout << "Returned: " << sensor->readDataStr(1024) << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "Timed out waiting for response" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a GroveGPRS Module on UART 0
|
||||||
|
upm::GroveGPRS* sensor = new upm::GroveGPRS(0);
|
||||||
|
|
||||||
|
// Set the baud rate, 19200 baud is the default.
|
||||||
|
if (sensor->setBaudRate(19200) != mraa::SUCCESS)
|
||||||
|
{
|
||||||
|
cerr << "Failed to set tty baud rate" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printUsage(argv[0]);
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
cout << "Sending command line argument (" << argv[1] << ")..." << endl;
|
||||||
|
sendCommand(sensor, argv[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// query the module manufacturer
|
||||||
|
cout << "Querying module manufacturer (AT+CGMI)..." << endl;
|
||||||
|
sendCommand(sensor, "AT+CGMI");
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
// query the saved profiles
|
||||||
|
cout << "Querying the saved profiles (AT&V)..." << endl;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
63
examples/c++/grovegsr.cxx
Normal file
63
examples/c++/grovegsr.cxx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grovegsr.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with the GroveGSR Galvanic Skin Response Sensor module.
|
||||||
|
|
||||||
|
// Instantiate a GroveGSR on analog pin A0
|
||||||
|
upm::GroveGSR *gsr = new upm::GroveGSR(0);
|
||||||
|
cout << "Calibrating...." << endl;
|
||||||
|
gsr->calibrate();
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
cout << gsr->value() << endl;
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
delete gsr;
|
||||||
|
return 0;
|
||||||
|
}
|
55
examples/c++/groveled.cxx
Normal file
55
examples/c++/groveled.cxx
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Contributions: 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Create the Grove LED object using GPIO pin 2
|
||||||
|
upm::GroveLed* led = new upm::GroveLed(2);
|
||||||
|
|
||||||
|
// Print the name
|
||||||
|
std::cout << led->name() << std::endl;
|
||||||
|
|
||||||
|
// Turn the LED on and off 10 times, pausing one second
|
||||||
|
// between transitions
|
||||||
|
for (int i=0; i < 10; i++) {
|
||||||
|
led->on();
|
||||||
|
sleep(1);
|
||||||
|
led->off();
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the Grove LED object
|
||||||
|
delete led;
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
49
examples/c++/grovelight.cxx
Normal file
49
examples/c++/grovelight.cxx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Contributions: 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
// Create the light sensor object using AIO pin 0
|
||||||
|
upm::GroveLight* light = new upm::GroveLight(0);
|
||||||
|
|
||||||
|
// Read the input and print both the raw value and a rough lux value,
|
||||||
|
// waiting one second between readings
|
||||||
|
while( 1 ) {
|
||||||
|
std::cout << light->name() << " raw value is " << light->raw_value() <<
|
||||||
|
", which is roughly " << light->value() << " lux" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the light sensor object
|
||||||
|
delete light;
|
||||||
|
//! [Interesting]
|
||||||
|
return 0;
|
||||||
|
}
|
75
examples/c++/grovemoisture.cxx
Normal file
75
examples/c++/grovemoisture.cxx
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grovemoisture.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Grove Moisture sensor on analog pin A0
|
||||||
|
upm::GroveMoisture* moisture = new upm::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
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
int val = moisture->value();
|
||||||
|
cout << "Moisture value: " << val << ", ";
|
||||||
|
if (val >= 0 && val < 300)
|
||||||
|
cout << "dry";
|
||||||
|
else if (val >= 300 && val < 600)
|
||||||
|
cout << "moist";
|
||||||
|
else
|
||||||
|
cout << "wet";
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
delete moisture;
|
||||||
|
return 0;
|
||||||
|
}
|
57
examples/c++/groveo2.cxx
Normal file
57
examples/c++/groveo2.cxx
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "groveo2.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with the O2 Oxygen Concentration Sensor Module
|
||||||
|
// Instantiate a GroveO2 on analog pin A0
|
||||||
|
upm::GroveO2 *O2 = new upm::GroveO2(0);
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
cout << "The output voltage is: " << O2->voltageValue() << "mV" << endl;
|
||||||
|
usleep(100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
delete O2;
|
||||||
|
return 0;
|
||||||
|
}
|
58
examples/c++/groverelay.cxx
Normal file
58
examples/c++/groverelay.cxx
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// This example uses GPIO 0
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Create the relay switch object using GPIO pin 0
|
||||||
|
upm::GroveRelay* relay = new upm::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.
|
||||||
|
for ( int i = 0; i < 3; i++ ) {
|
||||||
|
relay->on();
|
||||||
|
if ( relay->isOn() )
|
||||||
|
std::cout << relay->name() << " is on" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
relay->off();
|
||||||
|
if ( relay->isOff() )
|
||||||
|
std::cout << relay->name() << " is off" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the relay switch object
|
||||||
|
delete relay;
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
57
examples/c++/groverotary.cxx
Normal file
57
examples/c++/groverotary.cxx
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a rotary sensor on analog pin A0
|
||||||
|
upm::GroveRotary* knob = new upm::GroveRotary(0);
|
||||||
|
|
||||||
|
// Print sensor name to confirm it initialized properly
|
||||||
|
cout << knob->name() << endl;
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
float abs_value = knob->abs_value(); // Absolute raw value
|
||||||
|
float abs_deg = knob->abs_deg(); // Absolute degrees
|
||||||
|
float abs_rad = knob->abs_rad(); // Absolute radians
|
||||||
|
float rel_value = knob->rel_value(); // Relative raw value
|
||||||
|
float rel_deg = knob->rel_deg(); // Relative degrees
|
||||||
|
float rel_rad = knob->rel_rad(); // Relative radians
|
||||||
|
|
||||||
|
fprintf(stdout, "Absolute: %4d raw %5.2f deg = %3.2f rad Relative: %4d raw %5.2f deg %3.2f rad\n",
|
||||||
|
(int16_t)abs_value, abs_deg, abs_rad, (int16_t)rel_value, rel_deg, rel_rad);
|
||||||
|
|
||||||
|
usleep(2500000); // Sleep for 2.5s
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
delete knob;
|
||||||
|
return 0;
|
||||||
|
}
|
50
examples/c++/groveslide.cxx
Normal file
50
examples/c++/groveslide.cxx
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
upm::GroveSlide* slide = new upm::GroveSlide(0); // Instantiate new grove slide potentiometer on analog pin A0
|
||||||
|
|
||||||
|
cout << slide->name() << endl;
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
float adc_value = slide->raw_value(); // Read raw value
|
||||||
|
float volts = slide->voltage_value(); // Read voltage, board reference set at 5.0V
|
||||||
|
fprintf(stdout, "%4d = %.2f V\n", (uint16_t)adc_value, volts);
|
||||||
|
|
||||||
|
usleep(2500000); // Sleep for 2.5s
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
delete slide;
|
||||||
|
return 0;
|
||||||
|
}
|
49
examples/c++/grovespeaker.cxx
Normal file
49
examples/c++/grovespeaker.cxx
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grovespeaker.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Grove Speaker on digital pin D2
|
||||||
|
upm::GroveSpeaker* speaker = new upm::GroveSpeaker(2);
|
||||||
|
|
||||||
|
// Play all 7 of the lowest notes
|
||||||
|
speaker->playAll();
|
||||||
|
|
||||||
|
// Play a medium C-sharp
|
||||||
|
speaker->playSound('c', true, "med");
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting" << endl;
|
||||||
|
|
||||||
|
delete speaker;
|
||||||
|
return 0;
|
||||||
|
}
|
55
examples/c++/grovetemp.cxx
Normal file
55
examples/c++/grovetemp.cxx
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Contributions: 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include "grove.hpp"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Create the temperature sensor object using AIO pin 0
|
||||||
|
upm::GroveTemp* temp = new upm::GroveTemp(0);
|
||||||
|
std::cout << temp->name() << std::endl;
|
||||||
|
|
||||||
|
// Read the temperature ten times, printing both the Celsius and
|
||||||
|
// equivalent Fahrenheit temperature, waiting one second between readings
|
||||||
|
for (int i=0; i < 10; i++) {
|
||||||
|
int celsius = temp->value();
|
||||||
|
int fahrenheit = (int) (celsius * 9.0/5.0 + 32.0);
|
||||||
|
printf("%d degrees Celsius, or %d degrees Fahrenheit\n",
|
||||||
|
celsius, fahrenheit);
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the temperature sensor object
|
||||||
|
delete temp;
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
67
examples/c++/grovevdiv.cxx
Normal file
67
examples/c++/grovevdiv.cxx
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grovevdiv.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Grove Voltage Divider sensor on analog pin A0
|
||||||
|
upm::GroveVDiv* vDiv = new upm::GroveVDiv(0);
|
||||||
|
|
||||||
|
// collect data and output measured voltage according to the setting
|
||||||
|
// of the scaling switch (3 or 10)
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
unsigned int val = vDiv->value(100);
|
||||||
|
float gain3val = vDiv->computedValue(3, val);
|
||||||
|
float gain10val = vDiv->computedValue(10, val);
|
||||||
|
cout << "ADC value: " << val << " Gain 3: " << gain3val
|
||||||
|
<< "v Gain 10: " << gain10val << "v" << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete vDiv;
|
||||||
|
return 0;
|
||||||
|
}
|
65
examples/c++/grovewater.cxx
Normal file
65
examples/c++/grovewater.cxx
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "grovewater.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Grove Water sensor on digital pin D2
|
||||||
|
upm::GroveWater* water = new upm::GroveWater(2);
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
bool val = water->isWet();
|
||||||
|
if (val)
|
||||||
|
cout << "Sensor is wet." << endl;
|
||||||
|
else
|
||||||
|
cout << "Sensor is dry." << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete water;
|
||||||
|
return 0;
|
||||||
|
}
|
@ -31,30 +31,47 @@ add_example(DS1307Sample ds1307)
|
|||||||
add_example(ENC03RSample enc03r)
|
add_example(ENC03RSample enc03r)
|
||||||
add_example(ES08ASample servo)
|
add_example(ES08ASample servo)
|
||||||
add_example(ButtonSample button)
|
add_example(ButtonSample button)
|
||||||
|
add_example(GroveButtonSample grove)
|
||||||
add_example(Button_intrSample button)
|
add_example(Button_intrSample button)
|
||||||
|
add_example(GroveButton_intrSample grove)
|
||||||
add_example(Collision collision)
|
add_example(Collision collision)
|
||||||
add_example(EHRSample ehr)
|
add_example(EHRSample ehr)
|
||||||
|
add_example(GroveEHRSample groveehr)
|
||||||
add_example(Emg emg)
|
add_example(Emg emg)
|
||||||
|
add_example(GroveEmg groveemg)
|
||||||
add_example(Gsr gsr)
|
add_example(Gsr gsr)
|
||||||
|
add_example(GroveGsr grovegsr)
|
||||||
add_example(GroveLed_multiSample grove)
|
add_example(GroveLed_multiSample grove)
|
||||||
add_example(LEDSample led)
|
add_example(LEDSample led)
|
||||||
add_example(LightSample light)
|
add_example(LightSample light)
|
||||||
|
add_example(GroveLightSample grove)
|
||||||
add_example(GroveLineFinderSample grovelinefinder)
|
add_example(GroveLineFinderSample grovelinefinder)
|
||||||
|
add_example(GroveLed_multiSample grove)
|
||||||
|
add_example(GroveLEDSample grove)
|
||||||
add_example(GroveMDSample grovemd)
|
add_example(GroveMDSample grovemd)
|
||||||
add_example(MoistureSample moisture)
|
add_example(MoistureSample moisture)
|
||||||
|
add_example(GroveMoistureSample grovemoisture)
|
||||||
add_example(GroveMQ3 gas)
|
add_example(GroveMQ3 gas)
|
||||||
add_example(GroveMQ9 gas)
|
add_example(GroveMQ9 gas)
|
||||||
add_example(O2Example o2)
|
add_example(O2Example o2)
|
||||||
|
add_example(GroveO2Example groveo2)
|
||||||
add_example(GroveQTouch at42qt1070)
|
add_example(GroveQTouch at42qt1070)
|
||||||
add_example(RelaySample relay)
|
add_example(RelaySample relay)
|
||||||
|
add_example(GroveRelaySample grove)
|
||||||
add_example(RotarySample rotary)
|
add_example(RotarySample rotary)
|
||||||
|
add_example(GroveRotarySample grove)
|
||||||
add_example(GROVESCAMSample grovescam)
|
add_example(GROVESCAMSample grovescam)
|
||||||
add_example(SCAMSample scam)
|
add_example(SCAMSample scam)
|
||||||
add_example(SlideSample slide)
|
add_example(SlideSample slide)
|
||||||
|
add_example(GroveSlideSample grove)
|
||||||
add_example(SpeakerSample speaker)
|
add_example(SpeakerSample speaker)
|
||||||
|
add_example(GroveSpeakerSample grovespeaker)
|
||||||
add_example(TemperatureSample temperature)
|
add_example(TemperatureSample temperature)
|
||||||
|
add_example(GroveTempSample grove)
|
||||||
add_example(VDivSample vdiv)
|
add_example(VDivSample vdiv)
|
||||||
|
add_example(GroveVDivSample grovevdiv)
|
||||||
add_example(WaterSample water)
|
add_example(WaterSample water)
|
||||||
|
add_example(GroveWaterSample grovewater)
|
||||||
add_example(GroveWFSSample grovewfs)
|
add_example(GroveWFSSample grovewfs)
|
||||||
add_example(GUVAS12DSample guvas12d)
|
add_example(GUVAS12DSample guvas12d)
|
||||||
add_example(H3LIS331DLSample h3lis331dl)
|
add_example(H3LIS331DLSample h3lis331dl)
|
||||||
|
40
examples/java/GroveButtonSample.java
Normal file
40
examples/java/GroveButtonSample.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveButtonSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Create the button object using GPIO pin 2
|
||||||
|
upm_grove.GroveButton button = new upm_grove.GroveButton(2);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println(button.name() + " value is " + button.value());
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
examples/java/GroveButton_intrSample.java
Normal file
53
examples/java/GroveButton_intrSample.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveButton_intrSample {
|
||||||
|
|
||||||
|
public static int counter = 0;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
upm_grove.GroveButton b = new upm_grove.GroveButton(2);
|
||||||
|
|
||||||
|
ButtonISR callback = new ButtonISR();
|
||||||
|
b.installISR(2, callback);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.println("Counter: " + counter);
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ButtonISR implements Runnable {
|
||||||
|
public ButtonISR() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
GroveButton_intrSample.counter++;
|
||||||
|
System.out.println("Button pressed!");
|
||||||
|
}
|
||||||
|
}
|
48
examples/java/GroveCollision.java
Normal file
48
examples/java/GroveCollision.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_grovecollision.*;
|
||||||
|
|
||||||
|
public class GroveCollision {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Initializing the sensor on D2 on the Base Shield
|
||||||
|
upm_grovecollision.GroveCollision collision = new upm_grovecollision.GroveCollision(2);
|
||||||
|
boolean collisionState = false;
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
while(true){
|
||||||
|
if(collision.isColliding() && !collisionState){
|
||||||
|
System.out.println("Collision!!");
|
||||||
|
collisionState = true;
|
||||||
|
}
|
||||||
|
else if (collisionState){
|
||||||
|
System.out.println("No Collision!");
|
||||||
|
collisionState = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
examples/java/GroveEHRSample.java
Normal file
53
examples/java/GroveEHRSample.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//NOT TESTED!!!
|
||||||
|
public class GroveEHRSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
|
||||||
|
upm_groveehr.GroveEHR heart = new upm_groveehr.GroveEHR(2);
|
||||||
|
|
||||||
|
// set the beat counter to 0, init the clock and start counting beats
|
||||||
|
heart.clearBeatCounter();
|
||||||
|
heart.initClock();
|
||||||
|
heart.startBeatCounter();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
long millis = heart.getMillis();
|
||||||
|
long beats = heart.beatCounter();
|
||||||
|
|
||||||
|
// heartRate() requires that at least 5 seconds pass before
|
||||||
|
// returning anything other than 0
|
||||||
|
int hr = heart.heartRate();
|
||||||
|
|
||||||
|
// output milliseconds passed, beat count, and computed heart rate
|
||||||
|
System.out.println("Millis: " + millis + ", Beats: " + beats + ", Heart rate: " + hr);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
47
examples/java/GroveEmg.java
Normal file
47
examples/java/GroveEmg.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@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.
|
||||||
|
*/
|
||||||
|
import upm_groveemg.GroveEMG;
|
||||||
|
|
||||||
|
public class GroveEmg {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiating the Grove EMG sensor on Analog pin 0
|
||||||
|
GroveEMG emg = new GroveEMG(0);
|
||||||
|
System.out.println("Calibrating ... ");
|
||||||
|
emg.calibrate();
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
System.out.println("EMG Val: "+emg.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
50
examples/java/GroveGsr.java
Normal file
50
examples/java/GroveGsr.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_grovegsr.GroveGSR;
|
||||||
|
|
||||||
|
public class GroveGsr {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Grove GSR sensor on analog pin A0
|
||||||
|
GroveGSR gsr = new GroveGSR(0);
|
||||||
|
System.out.println("Calibrating...");
|
||||||
|
gsr.calibrate();
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
System.out.println("Value: "+gsr.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
examples/java/GroveLEDSample.java
Normal file
39
examples/java/GroveLEDSample.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Author: Andrei Vasiliu <andrei.vasiliu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveLEDSample {
|
||||||
|
public static void main (String args[]) throws InterruptedException {
|
||||||
|
//! [Interesting]
|
||||||
|
upm_grove.GroveLed led = new upm_grove.GroveLed(2);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
led.on();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
led.off();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
led.delete();
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
41
examples/java/GroveLightSample.java
Normal file
41
examples/java/GroveLightSample.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveLightSample {
|
||||||
|
public static void main(String args[]) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
upm_grove.GroveLight gl = new upm_grove.GroveLight(2);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
float raw_value = gl.raw_value();
|
||||||
|
float value = gl.value();
|
||||||
|
|
||||||
|
System.out.println("raw value: " + raw_value);
|
||||||
|
System.out.println("value: " + value);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
47
examples/java/GroveMoistureSample.java
Normal file
47
examples/java/GroveMoistureSample.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveMoistureSample {
|
||||||
|
public static void main(String args[]) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
upm_grovemoisture.GroveMoisture gm = new upm_grovemoisture.GroveMoisture(1);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int moisture_val = gm.value();
|
||||||
|
String result;
|
||||||
|
|
||||||
|
if (moisture_val >= 0 && moisture_val < 300)
|
||||||
|
result = "Dry";
|
||||||
|
else if ((moisture_val >= 0 && moisture_val < 300))
|
||||||
|
result = "Moist";
|
||||||
|
else
|
||||||
|
result = "Wet";
|
||||||
|
|
||||||
|
System.out.println("Moisture Value: " + moisture_val + ", " + result);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
46
examples/java/GroveO2Example.java
Normal file
46
examples/java/GroveO2Example.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_groveo2.GroveO2;
|
||||||
|
|
||||||
|
public class GroveO2Example {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Initializing the Grove O2 sensor on the A) analog pin
|
||||||
|
GroveO2 o2 = new GroveO2(0);
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
System.out.println("The output voltage is: "+o2.voltageValue());
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception has occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
44
examples/java/GroveRelaySample.java
Normal file
44
examples/java/GroveRelaySample.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveRelaySample {
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Create the button object using UART
|
||||||
|
upm_grove.GroveRelay relay = new upm_grove.GroveRelay(5);
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
relay.on();
|
||||||
|
if (relay.isOn())
|
||||||
|
System.out.println("Relay is on");
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
relay.off();
|
||||||
|
if (relay.isOff())
|
||||||
|
System.out.println("Relay is off");
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
49
examples/java/GroveRotarySample.java
Normal file
49
examples/java/GroveRotarySample.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveRotarySample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
upm_grove.GroveRotary knob = new upm_grove.GroveRotary(0);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
float abs_value = knob.abs_value(); // Absolute raw value
|
||||||
|
float abs_deg = knob.abs_deg(); // Absolute degrees
|
||||||
|
float abs_rad = knob.abs_rad(); // Absolute radians
|
||||||
|
float rel_value = knob.rel_value(); // Relative raw value
|
||||||
|
float rel_deg = knob.rel_deg(); // Relative degrees
|
||||||
|
float rel_rad = knob.rel_rad(); // Relative radians
|
||||||
|
|
||||||
|
System.out.println("Absolute: " + abs_value + " raw, " + abs_deg + " deg, " + abs_rad
|
||||||
|
+ " rad");
|
||||||
|
System.out.println("Relative: " + rel_value + " raw, " + rel_deg + " deg, " + rel_rad
|
||||||
|
+ " rad");
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
42
examples/java/GroveSlideSample.java
Normal file
42
examples/java/GroveSlideSample.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Author: Andrei Vasiliu <andrei.vasiliu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveSlideSample {
|
||||||
|
public static void main (String args[]) throws InterruptedException {
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate new grove slide potentiometer on analog pin A0
|
||||||
|
upm_grove.GroveSlide slide = new upm_grove.GroveSlide(0);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
float raw_value = slide.raw_value();
|
||||||
|
float value = slide.voltage_value();
|
||||||
|
|
||||||
|
System.out.println("raw value: " + raw_value);
|
||||||
|
System.out.println("value: " + value);
|
||||||
|
|
||||||
|
Thread.sleep(2500);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
40
examples/java/GroveSpeakerSample.java
Normal file
40
examples/java/GroveSpeakerSample.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Author: Andrei Vasiliu <andrei.vasiliu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveSpeakerSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a Grove Speaker on digital pin D2
|
||||||
|
upm_grovespeaker.GroveSpeaker speaker = new upm_grovespeaker.GroveSpeaker(2);
|
||||||
|
|
||||||
|
// Play all 7 of the lowest notes
|
||||||
|
speaker.playAll();
|
||||||
|
|
||||||
|
// Play a medium C-sharp
|
||||||
|
speaker.playSound('c', true, "med");
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
examples/java/GroveTempSample.java
Normal file
43
examples/java/GroveTempSample.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Author: Andrei Vasiliu <andrei.vasiliu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveTempSample {
|
||||||
|
public static void main (String args[]) throws InterruptedException {
|
||||||
|
//! [Interesting]
|
||||||
|
upm_grove.GroveTemp temp = new upm_grove.GroveTemp(3);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
|
||||||
|
int celsius = temp.value();
|
||||||
|
int fahrneheit = celsius * 2 + 32;
|
||||||
|
|
||||||
|
System.out.println("Celsius: " + celsius);
|
||||||
|
System.out.println("Fahrneheit: " + fahrneheit);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
temp.delete();
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
50
examples/java/GroveVDivSample.java
Normal file
50
examples/java/GroveVDivSample.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//NOT TESTED!!!
|
||||||
|
public class GroveVDivSample {
|
||||||
|
private static final short gain3 = 3;
|
||||||
|
private static final short gain10 = 10;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a Grove Voltage Divider sensor on analog pin A0
|
||||||
|
upm_grovevdiv.GroveVDiv vDiv = new upm_grovevdiv.GroveVDiv(0);
|
||||||
|
|
||||||
|
// collect data and output measured voltage according to the setting
|
||||||
|
// of the scaling switch (3 or 10)
|
||||||
|
while (true) {
|
||||||
|
long val = vDiv.value(100);
|
||||||
|
float gain3val = vDiv.computedValue(gain3, val);
|
||||||
|
float gain10val = vDiv.computedValue(gain10, val);
|
||||||
|
|
||||||
|
System.out.println("ADC value: " + val + ", Gain 3: " + gain3val + "v, Gain 10: "
|
||||||
|
+ gain10val);
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
examples/java/GroveWaterSample.java
Normal file
45
examples/java/GroveWaterSample.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Author: Stefan Andritoiu <stefan.andritoiu@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GroveWaterSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a Grove Water sensor on digital pin D2
|
||||||
|
upm_grovewater.GroveWater water = new upm_grovewater.GroveWater(2);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
boolean val = water.isWet();
|
||||||
|
if (val) {
|
||||||
|
System.out.println("Sensor is wet");
|
||||||
|
} else {
|
||||||
|
System.out.println("Sensor is dry");
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
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);
|
||||||
|
});
|
35
examples/python/grovebutton.py
Normal file
35
examples/python/grovebutton.py
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.
|
||||||
|
|
||||||
|
import time
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# Create the button object using GPIO pin 0
|
||||||
|
button = grove.GroveButton(0)
|
||||||
|
|
||||||
|
# Read the input and print, waiting one second between readings
|
||||||
|
while 1:
|
||||||
|
print button.name(), ' value is ', button.value()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Delete the button object
|
||||||
|
del button
|
57
examples/python/grovecollision.py
Normal file
57
examples/python/grovecollision.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovecollision as upmGrovecollision
|
||||||
|
|
||||||
|
# The was tested with the Grove Collision Sensor
|
||||||
|
# Instantiate a Grove Collision on digital pin D2
|
||||||
|
myGrovecollision = upmGrovecollision.GroveCollision(2)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This lets you run code on exit,
|
||||||
|
# including functions from myGrovecollision
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
collisionState = False
|
||||||
|
print "No collision"
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
if (myGrovecollision.isColliding() and not collisionState):
|
||||||
|
print "Collision!"
|
||||||
|
collisionState = True
|
||||||
|
elif (not myGrovecollision.isColliding() and collisionState):
|
||||||
|
print "No collision"
|
||||||
|
collisionState = False
|
68
examples/python/groveehr.py
Normal file
68
examples/python/groveehr.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_groveehr as upmGroveehr
|
||||||
|
|
||||||
|
# Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
|
||||||
|
myHeartRateSensor = upmGroveehr.GroveEHR(2)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This lets you run code on exit,
|
||||||
|
# including functions from myHeartRateSensor
|
||||||
|
def exitHandler():
|
||||||
|
myHeartRateSensor.stopBeatCounter()
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
# set the beat counter to 0, init the clock and start counting beats
|
||||||
|
myHeartRateSensor.clearBeatCounter()
|
||||||
|
myHeartRateSensor.initClock()
|
||||||
|
myHeartRateSensor.startBeatCounter()
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
# we grab these (millis and flowCount) 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
|
||||||
|
fr = myHeartRateSensor.heartRate()
|
||||||
|
|
||||||
|
# output milliseconds passed, beat count, and computed heart rate
|
||||||
|
outputStr = "Millis: {0} Beats: {1} Heart Rate: {2}".format(
|
||||||
|
millis, beats, fr)
|
||||||
|
print outputStr
|
||||||
|
time.sleep(1)
|
57
examples/python/groveeldriver.py
Normal file
57
examples/python/groveeldriver.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_groveeldriver as upmGroveeldriver
|
||||||
|
|
||||||
|
# The was tested with the Grove El Driver Module
|
||||||
|
# Instantiate a Grove El Driver on digital pin D2
|
||||||
|
myEldriver = upmGroveeldriver.GroveElDriver(2)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit, including functions from myEldriver
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
myEldriver.off()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
lightState = True
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
if (lightState):
|
||||||
|
myEldriver.on()
|
||||||
|
else:
|
||||||
|
myEldriver.off()
|
||||||
|
lightState = not lightState
|
||||||
|
|
||||||
|
time.sleep(1)
|
60
examples/python/groveelectromagnet.py
Normal file
60
examples/python/groveelectromagnet.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_groveelectromagnet as upmGroveelectromagnet
|
||||||
|
|
||||||
|
# This was tested with the Grove Electromagnetic Module
|
||||||
|
# Instantiate a Grove Electromagnet on digital pin D2
|
||||||
|
myElectromagnet = upmGroveelectromagnet.GroveElectromagnet(2)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This lets you run code on exit,
|
||||||
|
# including functions from myElectromagnet
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
myElectromagnet.off()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
magnetState = False
|
||||||
|
|
||||||
|
# Turn magnet on and off every 5 seconds
|
||||||
|
while(1):
|
||||||
|
magnetState = not magnetState
|
||||||
|
if (magnetState):
|
||||||
|
myElectromagnet.on()
|
||||||
|
else:
|
||||||
|
myElectromagnet.off()
|
||||||
|
print "Turning magnet", ("on" if magnetState else "off")
|
||||||
|
|
||||||
|
time.sleep(5)
|
52
examples/python/groveemg.py
Normal file
52
examples/python/groveemg.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_groveemg as upmGroveemg
|
||||||
|
|
||||||
|
# Tested with the GroveEMG Muscle Signal Reader Sensor Module
|
||||||
|
# Instantiate a GroveEMG on analog pin A0
|
||||||
|
myEMG = upmGroveemg.GroveEMG(0)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This lets you run code on exit, including functions from myEMG
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
print "Calibrating...."
|
||||||
|
myEMG.calibrate()
|
||||||
|
|
||||||
|
while (1):
|
||||||
|
print myEMG.value()
|
||||||
|
time.sleep(.1)
|
86
examples/python/grovegprs.py
Normal file
86
examples/python/grovegprs.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovegprs as sensorObj
|
||||||
|
|
||||||
|
# Instantiate a GroveGPRS Module on UART 0
|
||||||
|
sensor = sensorObj.GroveGPRS(0)
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
# Set the baud rate, 19200 baud is the default.
|
||||||
|
if (sensor.setBaudRate(19200)):
|
||||||
|
print "Failed to set baud rate"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
usageStr = ("Usage:\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")
|
||||||
|
print usageStr
|
||||||
|
|
||||||
|
# simple helper function to send a command and wait for a response
|
||||||
|
def sendCommand(sensor, cmd):
|
||||||
|
# commands need to be terminated with a carriage return
|
||||||
|
cmd += "\r";
|
||||||
|
sensor.writeDataStr(cmd)
|
||||||
|
|
||||||
|
# wait up to 1 second
|
||||||
|
if (sensor.dataAvailable(1000)):
|
||||||
|
print "Returned: ",
|
||||||
|
print sensor.readDataStr(1024)
|
||||||
|
else:
|
||||||
|
print "Timed out waiting for response"
|
||||||
|
|
||||||
|
|
||||||
|
if (len(sys.argv) > 1):
|
||||||
|
print "Sending command line argument (" + sys.argv[1] + ")..."
|
||||||
|
sendCommand(sensor, sys.argv[1])
|
||||||
|
else:
|
||||||
|
# query the module manufacturer
|
||||||
|
print "Querying module manufacturer (AT+CGMI)..."
|
||||||
|
sendCommand(sensor, "AT+CGMI");
|
||||||
|
|
||||||
|
time.sleep(1);
|
||||||
|
|
||||||
|
# query the saved profiles
|
||||||
|
print "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
|
53
examples/python/grovegsr.py
Normal file
53
examples/python/grovegsr.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovegsr as upmGrovegsr
|
||||||
|
|
||||||
|
# Tested with the GroveGSR Galvanic Skin Response Sensor module.
|
||||||
|
|
||||||
|
# Instantiate a GroveGSR on analog pin A0
|
||||||
|
myGSR = upmGrovegsr.GroveGSR(0)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This lets you run code on exit, including functions from myGSR
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
print "Calibrating...."
|
||||||
|
myGSR.calibrate()
|
||||||
|
|
||||||
|
while (1):
|
||||||
|
print myGSR.value()
|
||||||
|
time.sleep(.5)
|
41
examples/python/groveled.py
Normal file
41
examples/python/groveled.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
import time
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# Create the Grove LED object using GPIO pin 2
|
||||||
|
led = grove.GroveLed(2)
|
||||||
|
|
||||||
|
# Print the name
|
||||||
|
print led.name()
|
||||||
|
|
||||||
|
# Turn the LED on and off 10 times, pausing one second
|
||||||
|
# between transitions
|
||||||
|
for i in range (0,10):
|
||||||
|
led.on()
|
||||||
|
time.sleep(1)
|
||||||
|
led.off()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Delete the Grove LED object
|
||||||
|
del led
|
37
examples/python/grovelight.py
Normal file
37
examples/python/grovelight.py
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.
|
||||||
|
|
||||||
|
import time
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# Create the light sensor object using AIO pin 0
|
||||||
|
light = grove.GroveLight(0)
|
||||||
|
|
||||||
|
# Read the input and print both the raw value and a rough lux value,
|
||||||
|
# waiting one second between readings
|
||||||
|
while 1:
|
||||||
|
print light.name() + " raw value is %d" % light.raw_value() + \
|
||||||
|
", which is roughly %d" % light.value() + " lux";
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Delete the light sensor object
|
||||||
|
del light
|
61
examples/python/grovemoisture.py
Normal file
61
examples/python/grovemoisture.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovemoisture as upmMoisture
|
||||||
|
|
||||||
|
# Instantiate a Grove Moisture sensor on analog pin A0
|
||||||
|
myMoisture = upmMoisture.GroveMoisture(0)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit, including functions from myMoisture
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
while(1):
|
||||||
|
moisture_val = myMoisture.value()
|
||||||
|
if (moisture_val >= 0 and moisture_val < 300):
|
||||||
|
result = "Dry"
|
||||||
|
elif (moisture_val >= 300 and moisture_val < 600):
|
||||||
|
result = "Moist"
|
||||||
|
else:
|
||||||
|
result = "Wet"
|
||||||
|
print "Moisture value: {0}, {1}".format(moisture_val, result)
|
||||||
|
time.sleep(1)
|
51
examples/python/groveo2.py
Normal file
51
examples/python/groveo2.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_groveo2 as upmGroveo2
|
||||||
|
|
||||||
|
# This was tested with the O2 Oxygen Concentration Sensor Module
|
||||||
|
# Instantiate a GroveO2 on analog pin A0
|
||||||
|
myGroveO2 = upmGroveo2.GroveO2(0)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This lets you run code on exit, including functions from myGroveO2
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
print "The output voltage is: {0}mV".format(
|
||||||
|
myGroveO2.voltageValue())
|
||||||
|
|
||||||
|
time.sleep(.1)
|
44
examples/python/groverelay.py
Normal file
44
examples/python/groverelay.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
import time
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# Create the relay switch object using GPIO pin 0
|
||||||
|
relay = grove.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.
|
||||||
|
for i in range (0,3):
|
||||||
|
relay.on()
|
||||||
|
if relay.isOn():
|
||||||
|
print relay.name(), 'is on'
|
||||||
|
time.sleep(1)
|
||||||
|
relay.off()
|
||||||
|
if relay.isOff():
|
||||||
|
print relay.name(), 'is off'
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Delete the relay switch object
|
||||||
|
del relay
|
45
examples/python/groverotary.py
Normal file
45
examples/python/groverotary.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# New knob on AIO pin 0
|
||||||
|
knob = grove.GroveRotary(0)
|
||||||
|
|
||||||
|
# Loop indefinitely
|
||||||
|
while True:
|
||||||
|
|
||||||
|
# Read values
|
||||||
|
abs = knob.abs_value()
|
||||||
|
absdeg = knob.abs_deg()
|
||||||
|
absrad = knob.abs_rad()
|
||||||
|
|
||||||
|
rel = knob.rel_value()
|
||||||
|
reldeg = knob.rel_deg()
|
||||||
|
relrad = knob.rel_rad()
|
||||||
|
|
||||||
|
print "Abs values: %4d" % int(abs) , " raw %4d" % int(absdeg), "deg = %5.2f" % absrad , " rad ",
|
||||||
|
print "Rel values: %4d" % int(rel) , " raw %4d" % int(reldeg), "deg = %5.2f" % relrad , " rad"
|
||||||
|
|
||||||
|
# Sleep for 2.5 s
|
||||||
|
sleep(2.5)
|
39
examples/python/groveslide.py
Normal file
39
examples/python/groveslide.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# New Grove Slider on AIO pin 0
|
||||||
|
slider = grove.GroveSlide(0)
|
||||||
|
|
||||||
|
# Loop indefinitely
|
||||||
|
while True:
|
||||||
|
|
||||||
|
# Read values
|
||||||
|
raw = slider.raw_value()
|
||||||
|
volts = slider.voltage_value()
|
||||||
|
|
||||||
|
print "Slider value: ", raw , " = %.2f" % volts , " V"
|
||||||
|
|
||||||
|
# Sleep for 2.5 s
|
||||||
|
sleep(2.5)
|
34
examples/python/grovespeaker.py
Normal file
34
examples/python/grovespeaker.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovespeaker as upmGrovespeaker
|
||||||
|
|
||||||
|
# Instantiate a Grove Speaker on digital pin D2
|
||||||
|
mySpeaker = upmGrovespeaker.GroveSpeaker(2)
|
||||||
|
|
||||||
|
# Play all 7 of the lowest notes
|
||||||
|
mySpeaker.playAll()
|
||||||
|
|
||||||
|
# Play a medium C-sharp
|
||||||
|
mySpeaker.playSound('c', True, "med")
|
41
examples/python/grovetemp.py
Normal file
41
examples/python/grovetemp.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
# Contributions: 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.
|
||||||
|
|
||||||
|
import time
|
||||||
|
import pyupm_grove as grove
|
||||||
|
|
||||||
|
# Create the temperature sensor object using AIO pin 0
|
||||||
|
temp = grove.GroveTemp(0)
|
||||||
|
print temp.name()
|
||||||
|
|
||||||
|
# Read the temperature ten times, printing both the Celsius and
|
||||||
|
# equivalent Fahrenheit temperature, waiting one second between readings
|
||||||
|
for i in range(0, 10):
|
||||||
|
celsius = temp.value()
|
||||||
|
fahrenheit = celsius * 9.0/5.0 + 32.0;
|
||||||
|
print "%d degrees Celsius, or %d degrees Fahrenheit" \
|
||||||
|
% (celsius, fahrenheit)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Delete the temperature sensor object
|
||||||
|
del temp
|
54
examples/python/grovevdiv.py
Normal file
54
examples/python/grovevdiv.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovevdiv as upmGrovevdiv
|
||||||
|
|
||||||
|
# Instantiate a Grove Voltage Divider sensor on analog pin A0
|
||||||
|
myVoltageDivider = upmGrovevdiv.GroveVDiv(0)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit,
|
||||||
|
# including functions from myVoltageDivider
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
val = myVoltageDivider.value(100)
|
||||||
|
gain3val = myVoltageDivider.computedValue(3, val)
|
||||||
|
gain10val = myVoltageDivider.computedValue(10, val)
|
||||||
|
print "ADC value: {0} Gain 3: {1}v Gain 10: {2}v".format(
|
||||||
|
val, gain3val, gain10val)
|
||||||
|
|
||||||
|
time.sleep(1)
|
51
examples/python/grovewater.py
Normal file
51
examples/python/grovewater.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_grovewater as upmGrovewater
|
||||||
|
|
||||||
|
# Instantiate a Grove Water sensor on digital pin D2
|
||||||
|
myWaterSensor = upmGrovewater.GroveWater(2)
|
||||||
|
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit, including functions from myWaterSensor
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
if (myWaterSensor.isWet()):
|
||||||
|
print "Sensor is wet"
|
||||||
|
else:
|
||||||
|
print "Sensor is dry"
|
||||||
|
time.sleep(1)
|
5
src/groveeldriver/CMakeLists.txt
Normal file
5
src/groveeldriver/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set (libname "groveeldriver")
|
||||||
|
set (libdescription "upm groveeldriver sensor module")
|
||||||
|
set (module_src ${libname}.cxx)
|
||||||
|
set (module_hpp ${libname}.hpp)
|
||||||
|
upm_module_init("-lrt")
|
62
src/groveeldriver/groveeldriver.cxx
Normal file
62
src/groveeldriver/groveeldriver.cxx
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Author: Zion Orent <sorent@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "groveeldriver.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveElDriver::GroveElDriver(int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_gpio = mraa_gpio_init(pin)) )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveElDriver::~GroveElDriver()
|
||||||
|
{
|
||||||
|
mraa_gpio_close(m_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroveElDriver::on()
|
||||||
|
{
|
||||||
|
mraa_result_t error = MRAA_SUCCESS;
|
||||||
|
error = mraa_gpio_write (m_gpio, HIGH);
|
||||||
|
if (error != MRAA_SUCCESS)
|
||||||
|
mraa_result_print(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroveElDriver::off()
|
||||||
|
{
|
||||||
|
mraa_result_t error = MRAA_SUCCESS;
|
||||||
|
error = mraa_gpio_write (m_gpio, LOW);
|
||||||
|
if (error != MRAA_SUCCESS)
|
||||||
|
mraa_result_print(error);
|
||||||
|
}
|
78
src/groveeldriver/groveeldriver.hpp
Normal file
78
src/groveeldriver/groveeldriver.hpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Author: Zion Orent <sorent@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.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mraa/gpio.h>
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
/**
|
||||||
|
* @brief Grove EL Driver Module library
|
||||||
|
* @defgroup groveeldriver libupm-groveeldriver
|
||||||
|
* @ingroup seeed gpio electric
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library groveeldriver
|
||||||
|
* @sensor groveeldriver
|
||||||
|
* @comname Grove EL Driver
|
||||||
|
* @type electric
|
||||||
|
* @man seeed
|
||||||
|
* @con gpio
|
||||||
|
*
|
||||||
|
* @brief API for the Grove EL Driver Module
|
||||||
|
*
|
||||||
|
* The Grove EL Driver allows you to easily light up an
|
||||||
|
* EL wire with just one single Grove cable.
|
||||||
|
*
|
||||||
|
* @image html groveeldriver.jpg
|
||||||
|
* @snippet groveeldriver.cxx Interesting
|
||||||
|
*/
|
||||||
|
class GroveElDriver {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove EL Driver constructor
|
||||||
|
*
|
||||||
|
* @param pin Digital pin to use
|
||||||
|
*/
|
||||||
|
GroveElDriver(int pin);
|
||||||
|
/**
|
||||||
|
* Grove EL Driver destructor
|
||||||
|
*/
|
||||||
|
~GroveElDriver();
|
||||||
|
/**
|
||||||
|
* Turns the EL wire on
|
||||||
|
*/
|
||||||
|
void on();
|
||||||
|
/**
|
||||||
|
* Turns the EL wire off
|
||||||
|
*/
|
||||||
|
void off();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mraa_gpio_context m_gpio;
|
||||||
|
};
|
||||||
|
}
|
19
src/groveeldriver/javaupm_groveeldriver.i
Normal file
19
src/groveeldriver/javaupm_groveeldriver.i
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
%module javaupm_groveeldriver
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "groveeldriver.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveeldriver.hpp"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_groveeldriver");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
8
src/groveeldriver/jsupm_groveeldriver.i
Normal file
8
src/groveeldriver/jsupm_groveeldriver.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module jsupm_groveeldriver
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "groveeldriver.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "groveeldriver.hpp"
|
11
src/groveeldriver/pyupm_groveeldriver.i
Normal file
11
src/groveeldriver/pyupm_groveeldriver.i
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
%module pyupm_groveeldriver
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
%include "groveeldriver.hpp"
|
||||||
|
%{
|
||||||
|
#include "groveeldriver.hpp"
|
||||||
|
%}
|
5
src/grovespeaker/CMakeLists.txt
Normal file
5
src/grovespeaker/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set (libname "grovespeaker")
|
||||||
|
set (libdescription "upm grovespeaker speaker module")
|
||||||
|
set (module_src ${libname}.cxx)
|
||||||
|
set (module_hpp ${libname}.hpp)
|
||||||
|
upm_module_init()
|
150
src/grovespeaker/grovespeaker.cxx
Normal file
150
src/grovespeaker/grovespeaker.cxx
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* Author: Zion Orent <sorent@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "grovespeaker.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GroveSpeaker::GroveSpeaker(int pin)
|
||||||
|
{
|
||||||
|
if ( !(m_gpio = mraa_gpio_init(pin)) )
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
|
|
||||||
|
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||||
|
m_note_list['a'] = storeNote(1136, 1073, 568, 536, 284, 268);
|
||||||
|
m_note_list['b'] = storeNote(1012, 0, 506, 0, 253, 0);
|
||||||
|
m_note_list['c'] = storeNote(1911, 1804, 956, 902, 478, 451);
|
||||||
|
m_note_list['d'] = storeNote(1703, 1607, 851, 804, 426, 402);
|
||||||
|
m_note_list['e'] = storeNote(1517, 0, 758, 0, 379, 0);
|
||||||
|
m_note_list['f'] = storeNote(1432, 1351, 716, 676, 358, 338);
|
||||||
|
m_note_list['g'] = storeNote(1276, 1204, 638, 602, 319, 301);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroveSpeaker::~GroveSpeaker()
|
||||||
|
{
|
||||||
|
mraa_gpio_close(m_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
|
NoteData GroveSpeaker::storeNote(int noteDelayLow, int noteDelayLowSharp,
|
||||||
|
int noteDelayMed, int noteDelayMedSharp,
|
||||||
|
int noteDelayHigh, int noteDelayHighSharp)
|
||||||
|
{
|
||||||
|
NoteData note;
|
||||||
|
note.delayTimeLow = noteDelayLow;
|
||||||
|
note.delayTimeLowSharp = noteDelayLowSharp;
|
||||||
|
note.delayTimeMed = noteDelayMed;
|
||||||
|
note.delayTimeMedSharp = noteDelayMedSharp;
|
||||||
|
note.delayTimeHigh = noteDelayHigh;
|
||||||
|
note.delayTimeHighSharp = noteDelayHighSharp;
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroveSpeaker::playAll()
|
||||||
|
{
|
||||||
|
playSound('c', false, "low");
|
||||||
|
usleep(200000);
|
||||||
|
playSound('d', false, "low");
|
||||||
|
usleep(200000);
|
||||||
|
playSound('e', false, "low");
|
||||||
|
usleep(200000);
|
||||||
|
playSound('f', false, "low");
|
||||||
|
usleep(200000);
|
||||||
|
playSound('g', false, "low");
|
||||||
|
usleep(500000);
|
||||||
|
playSound('a', false, "low");
|
||||||
|
usleep(500000);
|
||||||
|
playSound('b', false, "low");
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroveSpeaker::playSound(char letter, bool sharp, std::string vocalWeight)
|
||||||
|
{
|
||||||
|
std::map<char, NoteData>::iterator it = m_note_list.find(letter);
|
||||||
|
if(it == m_note_list.end())
|
||||||
|
{
|
||||||
|
std::cout << "The key " << letter << " doesn't exist." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NoteData nd = it->second;
|
||||||
|
int delayTime;
|
||||||
|
if (sharp)
|
||||||
|
{
|
||||||
|
if (vocalWeight.compare("low") == 0)
|
||||||
|
delayTime = nd.delayTimeLowSharp;
|
||||||
|
else if (vocalWeight.compare("med") == 0)
|
||||||
|
delayTime = nd.delayTimeMedSharp;
|
||||||
|
else if (vocalWeight.compare("high") == 0)
|
||||||
|
delayTime = nd.delayTimeHighSharp;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Correct voice weight values are low, med, or high"
|
||||||
|
<< std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (vocalWeight.compare("low") == 0)
|
||||||
|
delayTime = nd.delayTimeLow;
|
||||||
|
else if (vocalWeight.compare("med") == 0)
|
||||||
|
delayTime = nd.delayTimeMed;
|
||||||
|
else if (vocalWeight.compare("high") == 0)
|
||||||
|
delayTime = nd.delayTimeHigh;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Correct voice weight values are low, med, or high"
|
||||||
|
<< std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If delayTime is zero, that means you tried to choose a sharp note
|
||||||
|
// for a note that has no sharp
|
||||||
|
if (sharp && !delayTime)
|
||||||
|
{
|
||||||
|
std::cout << "The key " << letter << " doesn't have a sharp note."
|
||||||
|
<< std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sound(delayTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroveSpeaker::sound(int note_delay)
|
||||||
|
{
|
||||||
|
mraa_result_t error = MRAA_SUCCESS;
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
error = mraa_gpio_write (m_gpio, HIGH);
|
||||||
|
usleep(note_delay);
|
||||||
|
error = mraa_gpio_write (m_gpio, LOW);
|
||||||
|
usleep(note_delay);
|
||||||
|
}
|
||||||
|
if (error != MRAA_SUCCESS)
|
||||||
|
mraa_result_print(error);
|
||||||
|
}
|
||||||
|
|
103
src/grovespeaker/grovespeaker.hpp
Normal file
103
src/grovespeaker/grovespeaker.hpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Author: Zion Orent <sorent@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.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <mraa/gpio.h>
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
/**
|
||||||
|
* @brief Grove Speaker library
|
||||||
|
* @defgroup grovespeaker libupm-grovespeaker
|
||||||
|
* @ingroup seeed gpio sound hak
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int delayTimeLow;
|
||||||
|
int delayTimeLowSharp;
|
||||||
|
int delayTimeMed;
|
||||||
|
int delayTimeMedSharp;
|
||||||
|
int delayTimeHigh;
|
||||||
|
int delayTimeHighSharp;
|
||||||
|
} NoteData;
|
||||||
|
/**
|
||||||
|
* @library grovespeaker
|
||||||
|
* @sensor grovespeaker
|
||||||
|
* @comname Grove Speaker
|
||||||
|
* @type sound
|
||||||
|
* @man seeed
|
||||||
|
* @con gpio
|
||||||
|
* @kit hak
|
||||||
|
*
|
||||||
|
* @brief API for the Grove Speaker
|
||||||
|
*
|
||||||
|
* UPM module for the Grove Speaker.
|
||||||
|
* This sensor can generate different tones and sounds depending on the
|
||||||
|
* frequency of the input signal.
|
||||||
|
*
|
||||||
|
* @image html grovespeaker.jpg
|
||||||
|
* @snippet grovespeaker.cxx Interesting
|
||||||
|
*/
|
||||||
|
class GroveSpeaker {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Grove Speaker constructor
|
||||||
|
*
|
||||||
|
* @param pin Digital pin to use
|
||||||
|
*/
|
||||||
|
GroveSpeaker(int pin);
|
||||||
|
/**
|
||||||
|
* GroveSpeaker destructor
|
||||||
|
*/
|
||||||
|
~GroveSpeaker();
|
||||||
|
/**
|
||||||
|
* Plays all alto notes (lowest notes)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void playAll();
|
||||||
|
/**
|
||||||
|
* Plays a sound and a note whether it's sharp or not
|
||||||
|
*
|
||||||
|
* @param letter Character name of the note
|
||||||
|
* ('a', 'b', 'c', 'd', 'e', 'f', or 'g')
|
||||||
|
* @param sharp If true, plays a sharp version of the note; otherwise, does not play the note
|
||||||
|
* @param vocalWeight String to determine whether to play a low ("low"),
|
||||||
|
* a medium ("med"), or a high ("high") note
|
||||||
|
*/
|
||||||
|
void playSound(char letter, bool sharp, std::string vocalWeight);
|
||||||
|
|
||||||
|
private:
|
||||||
|
mraa_gpio_context m_gpio;
|
||||||
|
std::map <char, NoteData> m_note_list;
|
||||||
|
void sound(int note_delay);
|
||||||
|
NoteData storeNote(int noteDelayLow, int noteDelayLowSharp,
|
||||||
|
int noteDelayMed, int noteDelayMedSharp,
|
||||||
|
int noteDelayHigh, int noteDelayHighSharp);
|
||||||
|
};
|
||||||
|
}
|
19
src/grovespeaker/javaupm_grovespeaker.i
Normal file
19
src/grovespeaker/javaupm_grovespeaker.i
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
%module javaupm_grovespeaker
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "grovespeaker.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovespeaker.hpp"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_grovespeaker");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
8
src/grovespeaker/jsupm_grovespeaker.i
Normal file
8
src/grovespeaker/jsupm_grovespeaker.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module jsupm_grovespeaker
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "grovespeaker.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "grovespeaker.hpp"
|
11
src/grovespeaker/pyupm_grovespeaker.i
Normal file
11
src/grovespeaker/pyupm_grovespeaker.i
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
%module pyupm_grovespeaker
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
%include "grovespeaker.hpp"
|
||||||
|
%{
|
||||||
|
#include "grovespeaker.hpp"
|
||||||
|
%}
|
Loading…
x
Reference in New Issue
Block a user