No Description

l298.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 HBridge_lib = require('jsupm_l298');
  27. // Instantiate one of the 2 possible DC motors on a L298 Dual
  28. // H-Bridge. For controlling a stepper motor, see the l298-stepper
  29. // example.
  30. var myHBridge_obj = new HBridge_lib.L298(3, 4, 7);
  31. /*****************************
  32. * Instantiate H-bridge object
  33. ******************************/
  34. myHBridge_obj.goForward = function()
  35. {
  36. console.log("Starting motor at 50% for 3 seconds...");
  37. myHBridge_obj.setSpeed(50);
  38. myHBridge_obj.setDirection(HBridge_lib.L298.DIR_CW);
  39. myHBridge_obj.enable(true);
  40. };
  41. myHBridge_obj.reverseDirection = function()
  42. {
  43. console.log("Reversing direction...");
  44. myHBridge_obj.setDirection(HBridge_lib.L298.DIR_NONE); // fast stop
  45. myHBridge_obj.setDirection(HBridge_lib.L298.DIR_CCW);
  46. };
  47. myHBridge_obj.stop = function()
  48. {
  49. myHBridge_obj.setSpeed(0);
  50. myHBridge_obj.enable(false);
  51. };
  52. myHBridge_obj.quit = function()
  53. {
  54. myHBridge_obj = null;
  55. HBridge_lib.cleanUp();
  56. HBridge_lib = null;
  57. console.log("Exiting");
  58. process.exit(0);
  59. };
  60. /************************
  61. * Run H-bridge!
  62. *************************/
  63. myHBridge_obj.goForward();
  64. setTimeout(myHBridge_obj.reverseDirection, 3000);
  65. setTimeout(function()
  66. {
  67. myHBridge_obj.stop();
  68. myHBridge_obj.quit();
  69. }, 6000);