1/*jslint node:true, vars:true, bitwise:true, unparam:true */ 2/*jshint unused:true */ 3 4/* 5 * Author: Jon Trulson <jtrulson@ics.com> 6 * Copyright (c) 2015 Intel Corporation. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining 9 * a copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sublicense, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be 17 * included in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 */ 27 28var ringcoderObj = require('jsupm_rgbringcoder'); 29 30// There are a lot of pins to hook up. These pins are valid for the 31// Edison board, but may need to be adjusted for other platforms. 32 33// In order: 34// enable - 4 35// latch - 10 36// clear - 11 37// clock - 2 38// data - 9 39// switch - 7 40 41// red pwm - 3 42// green pwm - 5 43// blue pwm - 6 44 45// encA - 12 46// encB - 13 47var ringCoder = new ringcoderObj.RGBRingCoder(4, 10, 11, 2, 9, 7, 12, 13, 3, 48 5, 6); 49 50var spin = 0x0001; 51var oldState = false; 52var oldPos = 0; 53 54// Lets go green 55ringCoder.setRGBLED(0.99, 0.01, 0.99); 56 57setInterval(function() 58{ 59 // you spin me round... 60 if ((spin & 0xffff) == 0) 61 spin = 0x0001; 62 63 ringCoder.setRingLEDS(spin); 64 spin <<= 1; 65 66 // check button state 67 var bstate = ringCoder.getButtonState(); 68 if (bstate != oldState) 69 { 70 console.log("Button state changed from " + oldState + " to " 71 + bstate); 72 oldState = bstate; 73 } 74 75 // check encoder position 76 var epos = ringCoder.getEncoderPosition(); 77 if (epos != oldPos) 78 { 79 console.log("Encoder position changed from " + oldPos + " to " 80 + epos); 81 oldPos = epos; 82 } 83}, 100); 84 85 86// exit on ^C 87process.on('SIGINT', function() 88{ 89 ringCoder = null; 90 ringcoderObj.cleanUp(); 91 ringcoderObj = null; 92 console.log("Exiting."); 93 process.exit(0); 94}); 95 96 97 98 99