2015-10-02 17:31:43 +03:00
|
|
|
/*
|
|
|
|
|
* Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
|
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2015-10-02 17:31:43 +03:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2015-10-02 17:31:43 +03:00
|
|
|
*/
|
|
|
|
|
|
2018-02-27 12:12:09 -08:00
|
|
|
public class A110X_intr_Example {
|
2015-10-02 17:31:43 +03:00
|
|
|
|
2018-10-11 20:06:13 -07:00
|
|
|
private static int counter=0;
|
|
|
|
|
|
|
|
|
|
public static void incrementCounter() {
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
2015-10-02 17:31:43 +03:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
// This example uses a user-supplied interrupt handler to count
|
|
|
|
|
// pulses that occur when a magnetic field of the correct polarity
|
|
|
|
|
// is detected. This could be used to measure the rotations per
|
|
|
|
|
// minute (RPM) of a rotor for example.
|
|
|
|
|
|
2016-01-28 15:36:29 -08:00
|
|
|
A110XISR callback = new A110XISR();
|
2015-10-02 17:31:43 +03:00
|
|
|
hall.installISR(callback);
|
|
|
|
|
|
|
|
|
|
while(true){
|
|
|
|
|
System.out.println("Counter: " + counter);
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
//! [Interesting]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 15:36:29 -08:00
|
|
|
class A110XISR implements Runnable {
|
2015-10-02 17:31:43 +03:00
|
|
|
public A110XISR(){
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
public void run(){
|
2018-10-11 20:06:13 -07:00
|
|
|
A110X_intr_Example.incrementCounter();
|
2015-10-02 17:31:43 +03:00
|
|
|
}
|
|
|
|
|
}
|