Brak opisu

uln200xa.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Jon Trulson <jtrulson@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 Uln200xa_lib = require('jsupm_uln200xa');
  27. // Instantiate a Stepper motor on a ULN200XA Darlington Motor Driver
  28. // This was tested with the Grove Geared Step Motor with Driver
  29. // Instantiate a ULN2003XA stepper object
  30. var myUln200xa_obj = new Uln200xa_lib.ULN200XA(4096, 8, 9, 10, 11);
  31. myUln200xa_obj.goForward = function()
  32. {
  33. myUln200xa_obj.setSpeed(5); // 5 RPMs
  34. myUln200xa_obj.setDirection(Uln200xa_lib.ULN200XA.DIR_CW);
  35. console.log("Rotating 1 revolution clockwise.");
  36. myUln200xa_obj.stepperSteps(4096);
  37. };
  38. myUln200xa_obj.reverseDirection = function()
  39. {
  40. console.log("Rotating 1/2 revolution counter clockwise.");
  41. myUln200xa_obj.setDirection(Uln200xa_lib.ULN200XA.DIR_CCW);
  42. myUln200xa_obj.stepperSteps(2048);
  43. };
  44. myUln200xa_obj.stop = function()
  45. {
  46. myUln200xa_obj.release();
  47. };
  48. myUln200xa_obj.quit = function()
  49. {
  50. myUln200xa_obj = null;
  51. Uln200xa_lib.cleanUp();
  52. Uln200xa_lib = null;
  53. console.log("Exiting");
  54. process.exit(0);
  55. };
  56. // Run ULN200xa driven stepper
  57. myUln200xa_obj.goForward();
  58. setTimeout(myUln200xa_obj.reverseDirection, 2000);
  59. setTimeout(function()
  60. {
  61. myUln200xa_obj.stop();
  62. myUln200xa_obj.quit();
  63. }, 2000);