No Description

A110X_intrSample.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
  3. * Copyright (c) 2015 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. public class A110X_intrSample {
  25. public static int counter=0;
  26. public static void main(String[] args) throws InterruptedException {
  27. //! [Interesting]
  28. // Instantiate an A110X sensor on digital pin D2
  29. upm_a110x.A110X hall = new upm_a110x.A110X(2);
  30. // This example uses a user-supplied interrupt handler to count
  31. // pulses that occur when a magnetic field of the correct polarity
  32. // is detected. This could be used to measure the rotations per
  33. // minute (RPM) of a rotor for example.
  34. A110XISR callback = new A110XISR();
  35. hall.installISR(callback);
  36. while(true){
  37. System.out.println("Counter: " + counter);
  38. Thread.sleep(1000);
  39. }
  40. //! [Interesting]
  41. }
  42. }
  43. class A110XISR implements Runnable {
  44. public A110XISR(){
  45. super();
  46. }
  47. public void run(){
  48. A110X_intrSample.counter++;
  49. }
  50. }