Browse Source

Java:Added example for Flex Sensor and added newly added sensors to the CMakeLists.txt

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
Abhishek Malik 9 years ago
parent
commit
1aa445b74e
2 changed files with 45 additions and 0 deletions
  1. 4
    0
      examples/java/CMakeLists.txt
  2. 41
    0
      examples/java/FlexSensorExample.java

+ 4
- 0
examples/java/CMakeLists.txt View File

@@ -101,6 +101,10 @@ add_example(WaterLevelSensor waterlevel)
101 101
 add_example(WT5001Sample wt5001)
102 102
 add_example(YG1006Sample yg1006)
103 103
 add_example(ZFM20Sample zfm20)
104
+add_example(Ad8232Example ad8232)
105
+add_example(Gp2y0aExample gp2y0a)
106
+add_example(Th02Example th02)
107
+add_example(FlexSensorExample flex)
104 108
 
105 109
 
106 110
 add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)

+ 41
- 0
examples/java/FlexSensorExample.java View File

@@ -0,0 +1,41 @@
1
+import upm_flex.Flex;
2
+
3
+public class FlexSensorExample {
4
+
5
+	static {
6
+		try {
7
+			System.loadLibrary("javaupm_flex");
8
+			System.loadLibrary("mraajava");
9
+		} catch (UnsatisfiedLinkError e) {
10
+			System.err.println(
11
+					"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
12
+							e);
13
+			System.exit(1);
14
+		}
15
+	}
16
+
17
+	public static void main(String[] args) {
18
+		// TODO Auto-generated method stub
19
+		//! [Interesting]
20
+		// The was tested with a Spectra Symbol flex sensor.
21
+		// We attached a 22K resistor to a breadboard,
22
+		// with 1 end attached to GND and the other connected to
23
+		// both the flex sensor and A0.
24
+		// The flex sensor was connected on 1 pin to the 22K resistor and A0
25
+		// and on the other pin to 5V.
26
+
27
+		// Instantiate a Flex sensor on analog pin A0
28
+		Flex flex = new Flex(0);
29
+		while(true){
30
+			System.out.println("Flex Sensor value is: "+flex.value());
31
+			try {
32
+				Thread.sleep(1000);
33
+			} catch (InterruptedException e) {
34
+				// TODO Auto-generated catch block
35
+				e.printStackTrace();
36
+			}
37
+		}
38
+		//! [Interesting]
39
+	}
40
+
41
+}