mirror of
https://github.com/eclipse/upm.git
synced 2025-07-02 01:41:12 +03:00
java: Added java examples for some sensors
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
9d63545d44
commit
5ff625eaf4
@ -23,29 +23,30 @@
|
||||
*/
|
||||
|
||||
public class A110XSample {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_a110x");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
}catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("error in loading native library");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
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...");
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
upm_a110x.A110X hall = new upm_a110x.A110X(2);
|
||||
|
||||
// check every second for the presence of a magnetic field (south polarity)
|
||||
while(true){
|
||||
if(hall.magnetDetected())
|
||||
System.out.println("Magnet (south polarity) detected.");
|
||||
else
|
||||
System.out.println("No magnet detected.");
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user