Grove: Reverted examples and Sources

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2016-09-13 17:29:02 -07:00
committed by Noel Eck
parent 4d39f1ee84
commit ea4b1b6aa7
88 changed files with 4447 additions and 0 deletions

View File

@ -31,30 +31,47 @@ add_example(DS1307Sample ds1307)
add_example(ENC03RSample enc03r)
add_example(ES08ASample servo)
add_example(ButtonSample button)
add_example(GroveButtonSample grove)
add_example(Button_intrSample button)
add_example(GroveButton_intrSample grove)
add_example(Collision collision)
add_example(EHRSample ehr)
add_example(GroveEHRSample groveehr)
add_example(Emg emg)
add_example(GroveEmg groveemg)
add_example(Gsr gsr)
add_example(GroveGsr grovegsr)
add_example(GroveLed_multiSample grove)
add_example(LEDSample led)
add_example(LightSample light)
add_example(GroveLightSample grove)
add_example(GroveLineFinderSample grovelinefinder)
add_example(GroveLed_multiSample grove)
add_example(GroveLEDSample grove)
add_example(GroveMDSample grovemd)
add_example(MoistureSample moisture)
add_example(GroveMoistureSample grovemoisture)
add_example(GroveMQ3 gas)
add_example(GroveMQ9 gas)
add_example(O2Example o2)
add_example(GroveO2Example groveo2)
add_example(GroveQTouch at42qt1070)
add_example(RelaySample relay)
add_example(GroveRelaySample grove)
add_example(RotarySample rotary)
add_example(GroveRotarySample grove)
add_example(GROVESCAMSample grovescam)
add_example(SCAMSample scam)
add_example(SlideSample slide)
add_example(GroveSlideSample grove)
add_example(SpeakerSample speaker)
add_example(GroveSpeakerSample grovespeaker)
add_example(TemperatureSample temperature)
add_example(GroveTempSample grove)
add_example(VDivSample vdiv)
add_example(GroveVDivSample grovevdiv)
add_example(WaterSample water)
add_example(GroveWaterSample grovewater)
add_example(GroveWFSSample grovewfs)
add_example(GUVAS12DSample guvas12d)
add_example(H3LIS331DLSample h3lis331dl)

View 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]
}
}

View 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!");
}
}

View 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]
}
}

View 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]
}
}

View 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]
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}

View 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]
}
}