diff --git a/examples/java/A110x_ex.java b/examples/java/A110x_ex.java new file mode 100644 index 00000000..4f1e741d --- /dev/null +++ b/examples/java/A110x_ex.java @@ -0,0 +1,24 @@ +public class A110x_ex { + static { + try { + System.loadLibrary("javaupm_a110x"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String argv[]) throws InterruptedException { + upm_a110x.A110X a110x = new upm_a110x.A110X(2); + + while(true) { + if(a110x.magnetDetected()) { + System.out.println("magnet detected..."); + } + else { + System.out.println("magnet not detected..."); + } + Thread.sleep(1000); + } + } +} diff --git a/examples/java/Adxl345.java b/examples/java/Adxl345.java new file mode 100644 index 00000000..cfc3167f --- /dev/null +++ b/examples/java/Adxl345.java @@ -0,0 +1,29 @@ +public class Adxl345 { + static { + try { + System.loadLibrary("javaupm_adxl345"); + } catch (UnsatisfiedLinkError e) { + System.err.println("error in loading native library"); + System.exit(-1); + } + } + + public static void main(String argv[]) throws InterruptedException { + upm_adxl345.Adxl345 obj = new upm_adxl345.Adxl345(0); + int[] raw = new int[3]; + float[] accel = new float[3]; + + while (true) { + obj.update(); + raw = obj.getRawValues(); + accel = obj.getAcceleration(); + + System.out.println("raw data: " + raw[0] + " " + raw[1] + " " + + raw[2]); + System.out.println("accel data: " + accel[0] + " " + accel[1] + " " + + accel[2]); + + Thread.sleep(1000); + } + } +}