diff --git a/examples/java/A110xSample.java b/examples/java/A110xSample.java index 8f4d2579..eafb4925 100644 --- a/examples/java/A110xSample.java +++ b/examples/java/A110xSample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 A110xSample { static { try { diff --git a/examples/java/Adxl345.java b/examples/java/Adxl345.java index cfc3167f..5308ea7c 100644 --- a/examples/java/Adxl345.java +++ b/examples/java/Adxl345.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 Adxl345 { static { try { diff --git a/examples/java/BISS0001Sample.java b/examples/java/BISS0001Sample.java index a6b2fcee..bf9d5c21 100644 --- a/examples/java/BISS0001Sample.java +++ b/examples/java/BISS0001Sample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 BISS0001Sample{ static { diff --git a/examples/java/BuzzerSample.java b/examples/java/BuzzerSample.java new file mode 100644 index 00000000..228434bc --- /dev/null +++ b/examples/java/BuzzerSample.java @@ -0,0 +1,64 @@ +/* + * Author: Stefan Andritoiu + * 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 BuzzerSample{ + + static { + try { + System.loadLibrary("javaupm_buzzer"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + int chord[] = { + upm_buzzer.javaupm_buzzer.DO, + upm_buzzer.javaupm_buzzer.RE, + upm_buzzer.javaupm_buzzer.MI, + upm_buzzer.javaupm_buzzer.FA, + upm_buzzer.javaupm_buzzer.SOL, + upm_buzzer.javaupm_buzzer.LA, + upm_buzzer.javaupm_buzzer.SI + }; + + // Instantiate a buzzer on digital pin D5 + upm_buzzer.Buzzer sound = new upm_buzzer.Buzzer(5); + + // print sensor name + System.out.println(sound.name()); + + for (int i = 0; i < chord.length; i++) { + // play each note for one second + int note = sound.playSound( chord[i], 1000000); + System.out.println(note); + + Thread.sleep(100); + } + sound.stopSound(); + } + + +} \ No newline at end of file diff --git a/examples/java/CJQ4435Sample.java b/examples/java/CJQ4435Sample.java new file mode 100644 index 00000000..2368ec57 --- /dev/null +++ b/examples/java/CJQ4435Sample.java @@ -0,0 +1,61 @@ +/* + * Author: Stefan Andritoiu + * 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 CJQ4435Sample{ + + static { + try { + System.loadLibrary("javaupm_cjq4435"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3 + upm_cjq4435.CJQ4435 mosfet = new upm_cjq4435.CJQ4435(3); + + mosfet.setPeriodMS(10); + mosfet.enable(true); + + while(true){ + // start with a duty cycle of 0.0 (off) and increment to 1.0 (on) + for (float i=0; i <= 1; i+=0.1){ + mosfet.setDutyCycle(i); + Thread.sleep(100); + } + Thread.sleep(1000); + + // Now take it back down + // start with a duty cycle of 1.0 (on) and decrement to 0.0 (off) + for (float i=1; i >= 0; i-=0.1){ + mosfet.setDutyCycle(i); + Thread.sleep(100); + } + Thread.sleep(1000); + } + } + +} \ No newline at end of file diff --git a/examples/java/ES08ASample.java b/examples/java/ES08ASample.java index 2e27bd13..e1d56965 100644 --- a/examples/java/ES08ASample.java +++ b/examples/java/ES08ASample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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_servo.ES08A; public class ES08ASample{ diff --git a/examples/java/GUVAS12DSample.java b/examples/java/GUVAS12DSample.java index e4d25bd1..8287a9da 100644 --- a/examples/java/GUVAS12DSample.java +++ b/examples/java/GUVAS12DSample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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_guvas12d.GUVAS12D; public class GUVAS12DSample{ diff --git a/examples/java/GroveButtonSample.java b/examples/java/GroveButtonSample.java index a3cd886a..11427c28 100644 --- a/examples/java/GroveButtonSample.java +++ b/examples/java/GroveButtonSample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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{ static { diff --git a/examples/java/GroveLEDSample.java b/examples/java/GroveLEDSample.java index 278e51fa..ea6c969e 100644 --- a/examples/java/GroveLEDSample.java +++ b/examples/java/GroveLEDSample.java @@ -1,3 +1,27 @@ +/* + * Author: Andrei Vasiliu + * 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 { static { try { diff --git a/examples/java/GroveLightSample.java b/examples/java/GroveLightSample.java index 9c43dfc3..cede39a5 100644 --- a/examples/java/GroveLightSample.java +++ b/examples/java/GroveLightSample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 { static { try { diff --git a/examples/java/GroveLineFinderSample.java b/examples/java/GroveLineFinderSample.java new file mode 100644 index 00000000..f5469298 --- /dev/null +++ b/examples/java/GroveLineFinderSample.java @@ -0,0 +1,53 @@ +/* + * Author: Stefan Andritoiu + * 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 GroveLineFinderSample{ + + static { + try { + System.loadLibrary("javaupm_grovelinefinder"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate a Grove Line Finder sensor on digital pin D2 + upm_grovelinefinder.GroveLineFinder finder = new upm_grovelinefinder.GroveLineFinder(2); + // check every second for the presence of white detection + while(true){ + boolean val = finder.whiteDetected(); + if(val){ + System.out.println("White detected"); + } + else{ + System.out.println("Black detected"); + } + + Thread.sleep(1000); + } + } + +} \ No newline at end of file diff --git a/examples/java/GroveMoistureSample.java b/examples/java/GroveMoistureSample.java index d4332681..555d8245 100644 --- a/examples/java/GroveMoistureSample.java +++ b/examples/java/GroveMoistureSample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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{ static { try { diff --git a/examples/java/GroveRelaySample.java b/examples/java/GroveRelaySample.java index 1fc7ac75..4453081e 100644 --- a/examples/java/GroveRelaySample.java +++ b/examples/java/GroveRelaySample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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{ static { try { diff --git a/examples/java/GroveRotarySample.java b/examples/java/GroveRotarySample.java index a9063c3a..db969bbe 100644 --- a/examples/java/GroveRotarySample.java +++ b/examples/java/GroveRotarySample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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{ static { diff --git a/examples/java/GroveSlideSample.java b/examples/java/GroveSlideSample.java index 5556b4ee..2a169fa4 100644 --- a/examples/java/GroveSlideSample.java +++ b/examples/java/GroveSlideSample.java @@ -1,3 +1,27 @@ +/* + * Author: Andrei Vasiliu + * 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 { static { try { @@ -9,7 +33,8 @@ public class GroveSlideSample { } public static void main (String args[]) throws InterruptedException { - upm_grove.GroveSlide slide = new upm_grove.GroveSlide(0); + // 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(); diff --git a/examples/java/GroveSpeakerSample.java b/examples/java/GroveSpeakerSample.java index a1a1e01b..5b92bec7 100644 --- a/examples/java/GroveSpeakerSample.java +++ b/examples/java/GroveSpeakerSample.java @@ -1,19 +1,47 @@ -public class GroveSpeakerSample { +/* + * Author: Andrei Vasiliu + * 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{ + static { try { System.loadLibrary("javaupm_grovespeaker"); - } catch (UnsatisfiedLinkError e) { + }catch (UnsatisfiedLinkError e) { System.err.println("error in loading native library"); System.exit(-1); } } - - public static void main (String args[]) throws InterruptedException { - upm_grovespeaker.GroveSpeaker speaker = new upm_grovespeaker.GroveSpeaker(3); + + public static void main(String[] args) throws InterruptedException { + // 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(); - speaker.playSound('c', true, "med"); - temp.delete(); + // Play a medium C-sharp + speaker.playSound('c', true, "med"); } + } diff --git a/examples/java/GroveTempSample.java b/examples/java/GroveTempSample.java index ec386dfe..33ca8cf3 100644 --- a/examples/java/GroveTempSample.java +++ b/examples/java/GroveTempSample.java @@ -1,3 +1,27 @@ +/* + * Author: Andrei Vasiliu + * 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 { static { try { diff --git a/examples/java/GroveWaterSample.java b/examples/java/GroveWaterSample.java new file mode 100644 index 00000000..535896d6 --- /dev/null +++ b/examples/java/GroveWaterSample.java @@ -0,0 +1,54 @@ +/* + * Author: Stefan Andritoiu + * 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{ + + static { + try { + System.loadLibrary("javaupm_grovewater"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // 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); + } + } + + +} \ No newline at end of file diff --git a/examples/java/Jhd1313m1Sample.java b/examples/java/Jhd1313m1Sample.java index b00a07f3..65d36e9e 100644 --- a/examples/java/Jhd1313m1Sample.java +++ b/examples/java/Jhd1313m1Sample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 Jhd1313m1Sample{ static { diff --git a/examples/java/MQ303ASample.java b/examples/java/MQ303ASample.java new file mode 100644 index 00000000..9f336b2a --- /dev/null +++ b/examples/java/MQ303ASample.java @@ -0,0 +1,62 @@ +/* + * Author: Stefan Andritoiu + * 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 MQ303ASample{ + + static { + try { + System.loadLibrary("javaupm_mq303a"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate an mq303a sensor on analog pin A0 + + // This device uses a heater powered from an analog I/O pin.· + // If using A0 as the data pin, then you need to use A1, as the heater + // pin (if using a grove mq303a). For A1, we can use the D15 gpio,· + // setup as an output, and drive it low to power the heater. + upm_mq303a.MQ303A mq303a = new upm_mq303a.MQ303A(1,15); + + System.out.println("Enabling heater and waiting 2 minutes for warmup."); + mq303a.heaterEnable(true); + Thread.sleep(120000); + + System.out.println("This sensor may need to warm until the value drops below about 450."); + + for(int i = 1 ; i < 10 ; i++){ + int val = mq303a.value(); + System.out.println("Alcohol detected (higher means stronger alcohol): " + val); + + Thread.sleep(1000); + } + + mq303a.heaterEnable(false); + System.out.println("Exiting"); + } + +} \ No newline at end of file diff --git a/examples/java/MY9221Sample.java b/examples/java/MY9221Sample.java new file mode 100644 index 00000000..54f54363 --- /dev/null +++ b/examples/java/MY9221Sample.java @@ -0,0 +1,48 @@ +/* + * Author: Stefan Andritoiu + * 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 MY9221Sample{ + + static { + try { + System.loadLibrary("javaupm_my9221"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9 + upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9); + + while (true) { + for (short idx = 1; idx < 11; idx++) { + bar.setBarLevel(idx); + Thread.sleep(100); + } + } + } + +} \ No newline at end of file diff --git a/examples/java/NUNCHUCKSample.java b/examples/java/NUNCHUCKSample.java new file mode 100644 index 00000000..0724a98d --- /dev/null +++ b/examples/java/NUNCHUCKSample.java @@ -0,0 +1,67 @@ +/* + * Author: Stefan Andritoiu + * 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 NUNCHUCKSample{ + + static { + try { + System.loadLibrary("javaupm_nunchuck"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate a nunchuck controller bus 0 + upm_nunchuck.NUNCHUCK nunchuck = new upm_nunchuck.NUNCHUCK(0); + + // always do this first + System.out.println("Initializing... "); + if (!nunchuck.init()) { + System.err.println("nunchuck->init() failed."); + return; + } + + while(true){ + nunchuck.update(); + System.out.println( "stickX: " + nunchuck.getStickX() + ", stickY: " + nunchuck.getStickY() ); + System.out.println( "accelX: " + nunchuck.getAccelX() + ", accelY: " + nunchuck.getAccelY() + +", accelZ: " + nunchuck.getAccelZ()); + + if(nunchuck.getButtonC()) + System.out.println("Button C pressed"); + else + System.out.println("Button C not pressed"); + + if(nunchuck.getButtonZ()) + System.out.println("Button Z pressed"); + else + System.out.println("Button Z not pressed"); + + Thread.sleep(1000); + } + } + +} \ No newline at end of file diff --git a/examples/java/OTP538USample.java b/examples/java/OTP538USample.java new file mode 100644 index 00000000..46b0de64 --- /dev/null +++ b/examples/java/OTP538USample.java @@ -0,0 +1,49 @@ +/* + * Author: Stefan Andritoiu + * 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 OTP538USample{ + private static final float OTP538U_AREF = 5; + + static { + try { + System.loadLibrary("javaupm_otp538u"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate a OTP538U on analog pins A0 and A1 + // A0 is used for the Ambient Temperature and A1 is used for the Object temperature. + upm_otp538u.OTP538U temps = new upm_otp538u.OTP538U(0, 1, OTP538U_AREF); + + while (true) { + System.out.println( "Ambient temp: " + temps.ambientTemperature() + " C" ); + System.out.println( "Object temp: " + temps.objectTemperature() + " C" ); + + Thread.sleep(1000); + } + } +} \ No newline at end of file diff --git a/examples/java/RFR359FSample.java b/examples/java/RFR359FSample.java new file mode 100644 index 00000000..09b4d2dc --- /dev/null +++ b/examples/java/RFR359FSample.java @@ -0,0 +1,52 @@ +/* + * Author: Stefan Andritoiu + * 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 RFR359FSample{ + + static { + try { + System.loadLibrary("javaupm_rfr359f"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate an RFR359F digital pin D2 + upm_rfr359f.RFR359F dInterruptor = new upm_rfr359f.RFR359F(2); + + while(true){ + if (dInterruptor.objectDetected()) { + System.out.println("Object detected"); + } + else{ + System.out.println("Area is clear!"); + } + + Thread.sleep(100); + } + } + +} \ No newline at end of file diff --git a/examples/java/RotaryEncoderSample.java b/examples/java/RotaryEncoderSample.java index 301cae4d..81f24eb4 100644 --- a/examples/java/RotaryEncoderSample.java +++ b/examples/java/RotaryEncoderSample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 RotaryEncoderSample{ static { diff --git a/examples/java/TP401Sample.java b/examples/java/TP401Sample.java new file mode 100644 index 00000000..6a7bbca6 --- /dev/null +++ b/examples/java/TP401Sample.java @@ -0,0 +1,69 @@ +/* + * Author: Stefan Andritoiu + * 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 TP401Sample{ + static { + try { + System.loadLibrary("javaupm_gas"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + private static String airQuality(int value){ + if(value < 50) return "Fresh Air"; + if(value < 200) return "Normal Indoor Air"; + if(value < 400) return "Low Pollution"; + if(value < 600) return "High Pollution - Action Recommended"; + return "Very High Pollution - Take Action Immediately"; + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate new grove air quality sensor on analog pin A0 + upm_gas.TP401 airSensor = new upm_gas.TP401(0); + + System.out.println(airSensor.name()); + + System.out.println("Heating sensor for 3 minutes..."); + // wait 3 minutes for sensor to warm up + for(int i = 0; i < 3; i++) { + if(i != 0) + System.out.println("Please wait, " + i + " minute(s) passed.."); + Thread.sleep(60000); + } + System.out.println( "Sensor ready!"); + + while(true){ + int value = airSensor.getSample(); // Read raw value + float ppm = airSensor.getPPM(); // Read CO ppm (can vary slightly from previous read) + + System.out.println("raw: " + value + " ppm: " + ppm + " " + airQuality(value) ); + + Thread.sleep(100); + } + } + + +} \ No newline at end of file diff --git a/examples/java/TTP223Sample.java b/examples/java/TTP223Sample.java index a5f5bd01..f82a80cb 100644 --- a/examples/java/TTP223Sample.java +++ b/examples/java/TTP223Sample.java @@ -1,3 +1,27 @@ +/* + * Author: Stefan Andritoiu + * 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 TTP223Sample{ static { diff --git a/examples/java/YG1006Sample.java b/examples/java/YG1006Sample.java new file mode 100644 index 00000000..624018c1 --- /dev/null +++ b/examples/java/YG1006Sample.java @@ -0,0 +1,53 @@ +/* + * Author: Stefan Andritoiu + * 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 YG1006Sample{ + + static { + try { + System.loadLibrary("javaupm_yg1006"); + }catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String[] args) throws InterruptedException { + // Instantiate a yg1006 flame sensor on digital pin D2 + upm_yg1006.YG1006 flame = new upm_yg1006.YG1006(2); + + while (true) { + boolean val = flame.flameDetected(); + if (val){ + System.out.println("Flame detected"); + } + else{ + System.out.println("No flame detected"); + } + + Thread.sleep(1000); + } + } + +} \ No newline at end of file