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