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 27function exit() 28{ 29 console.log("Exiting"); 30 31 myMotorShield_obj = null; 32 if (MotorShield_lib) 33 { 34 MotorShield_lib.cleanUp(); 35 MotorShield_lib = null; 36 } 37 process.exit(0); 38} 39 40var MotorShield_lib = require('jsupm_adafruitms1438'); 41 42/* Import header values */ 43var I2CBus = MotorShield_lib.ADAFRUITMS1438_I2C_BUS; 44var I2CAddr = MotorShield_lib.ADAFRUITMS1438_DEFAULT_I2C_ADDR; 45 46var M12motor = MotorShield_lib.AdafruitMS1438.STEPMOTOR_M12; 47var MotorDirCW = MotorShield_lib.AdafruitMS1438.DIR_CW; 48var MotorDirCCW = MotorShield_lib.AdafruitMS1438.DIR_CCW; 49 50 51// Instantiate an Adafruit MS 1438 on I2C bus 0 52var myMotorShield_obj = new MotorShield_lib.AdafruitMS1438(I2CBus, I2CAddr); 53 54 55// Setup for use with a stepper motor connected to the M1 & M2 ports 56 57// disable first, to be safe 58myMotorShield_obj.disableStepper(M12motor); 59 60// configure for a NEMA-17, 200 steps per revolution 61myMotorShield_obj.stepConfig(M12motor, 200); 62 63// set speed at 10 RPM's 64myMotorShield_obj.setStepperSpeed(M12motor, 10); 65myMotorShield_obj.setStepperDirection(M12motor, MotorDirCW); 66 67console.log("Enabling..."); 68myMotorShield_obj.enableStepper(M12motor); 69 70console.log("Rotating 1 full revolution at 10 RPM speed."); 71myMotorShield_obj.stepperSteps(M12motor, 200); 72 73console.log("Sleeping for 2 seconds..."); 74 75 76setTimeout(function() 77{ 78 console.log("Rotating 1/2 revolution in opposite direction at 10 RPM speed."); 79 80 myMotorShield_obj.setStepperDirection(M12motor, MotorDirCCW); 81 myMotorShield_obj.stepperSteps(M12motor, 100); 82 83 console.log("Disabling..."); 84 myMotorShield_obj.disableStepper(M12motor); 85 exit(); 86}, 2000); 87 88 89process.on('SIGINT', function() 90{ 91 exit(); 92}); 93