No Description

adxl335.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Zion Orent <zorent@ics.com>
  5. * Copyright (c) 2015 Intel Corporation.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. var analogGyro3Axis = require("jsupm_adxl335");
  27. var g_addnumBool = true;
  28. var g_cycleNum = 0.0;
  29. var g_cycleCount = 0;
  30. // Instantiate an ADXL335 accelerometer on analog pins A0, A1, and A2
  31. var myAnalogGyro3Axis = new analogGyro3Axis.ADXL335(0, 1, 2);
  32. console.log("Please make sure the sensor is completely still.");
  33. console.log("Sleeping for 2 seconds");
  34. var g_myInterval;
  35. setTimeout(function()
  36. {
  37. console.log("Calibrating...");
  38. myAnalogGyro3Axis.calibrate();
  39. // Get values from accelerometer every 0.2 seconds
  40. g_myInterval = setInterval(runAccelerometer, 200);
  41. }, 2000);
  42. var x = new analogGyro3Axis.intPointer(0);
  43. var y = new analogGyro3Axis.intPointer(0);
  44. var z = new analogGyro3Axis.intPointer(0);
  45. var aX = new analogGyro3Axis.floatPointer(0);
  46. var aY = new analogGyro3Axis.floatPointer(0);
  47. var aZ = new analogGyro3Axis.floatPointer(0);
  48. var outputStr;
  49. function runAccelerometer()
  50. {
  51. myAnalogGyro3Axis.values(x, y, z);
  52. outputStr = "Raw Values: X: " + x.getitem(0) +
  53. " Y: " + y.getitem(0) +
  54. " Z: " + z.getitem(0);
  55. console.log(outputStr);
  56. myAnalogGyro3Axis.acceleration(aX, aY, aZ);
  57. console.log("Acceleration: X: " + aX.getitem(0) + "g");
  58. console.log("Acceleration: Y: " + aY.getitem(0) + "g");
  59. console.log("Acceleration: Z: " + aZ.getitem(0) + "g");
  60. console.log(" ");
  61. }
  62. // When exiting: clear interval and print exit message
  63. process.on('SIGINT', function()
  64. {
  65. clearInterval(g_myInterval);
  66. console.log("Exiting...");
  67. process.exit(0);
  68. });