|
@@ -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
|
+}
|