No Description

BMI160_Example.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Author: Jon Trulson <jtrulson@ics.com>
  3. * Copyright (c) 2016 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. import upm_bmi160.BMI160;
  25. public class BMI160_Example
  26. {
  27. public static void main(String[] args) throws InterruptedException
  28. {
  29. // ! [Interesting]
  30. System.out.println("Initializing...");
  31. // Instantiate a BMI160 instance using default i2c bus and address
  32. BMI160 sensor = new BMI160();
  33. while (true)
  34. {
  35. // update our values from the sensor
  36. sensor.update();
  37. float dataA[] = sensor.getAccelerometer();
  38. System.out.println("Accelerometer: "
  39. + "AX: "
  40. + dataA[0]
  41. + " AY: "
  42. + dataA[1]
  43. + " AZ: "
  44. + dataA[2]);
  45. float dataG[] = sensor.getGyroscope();
  46. System.out.println("Gryoscope: "
  47. + "GX: "
  48. + dataG[0]
  49. + " GY: "
  50. + dataG[1]
  51. + " GZ: "
  52. + dataG[2]);
  53. float dataM[] = sensor.getMagnetometer();
  54. System.out.println("Magnetometer: "
  55. + "MX: "
  56. + dataM[0]
  57. + " MY: "
  58. + dataM[1]
  59. + " MZ: "
  60. + dataM[2]);
  61. System.out.println();
  62. Thread.sleep(500);
  63. }
  64. // ! [Interesting]
  65. }
  66. }