Created
July 12, 2012 01:45
-
-
Save mikeal/3095110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var serial = require('./lib/serial') | |
, Tpad = require('./lib/tpad') | |
; | |
serial.init() | |
var spinnerTimer = function () {} | |
serial.on('searching', function() { | |
process.stdout.write('searching '); | |
spinnerTimer = setInterval(function() { | |
process.stdout.write(spinner[spinnerPos]); | |
spinnerPos++; | |
if (spinnerPos >= spinner.length) { | |
spinnerPos = 0; | |
} | |
}, 50); | |
}); | |
serial.on('connected', function(config) { | |
clearInterval(spinnerTimer) | |
console.log('\n\nconnected to a', config.tpad.name, 'with', config.tpad.pads, 'pads') | |
var currentSerialPort = config.serialport | |
var tpad = new Tpad(config) | |
var colors = | |
[ '#1B28E0' | |
, '#E30B0B' | |
, '#07FA34' | |
, '#FAA507' | |
] | |
var index = 0 | |
, count = 0 | |
; | |
tpad.animate(200, [0,1,2,3], function(pad) { | |
tpad.color('000'); // turn all the lights off | |
pad.color(colors[index]); // turn the current pad red | |
count++ | |
if (count === 4) { | |
if (index === 3) index = 0 | |
else index++ | |
count = 0 | |
} | |
}); | |
// tpad.each(function(pad, index) { | |
// pad.color(colors.shift()) | |
// | |
// pad.on('pressure', function(p) { | |
// console.log('#'+(p.value * 3).toString(16)+'00') | |
// p.color('#'+(p.value * 3).toString(16)+'00') | |
// }); | |
// | |
// pad.on('press', function(p) { | |
// }); | |
// | |
// pad.on('depress', function(p) { | |
// }); | |
// }); | |
}); | |
serial.on('disconnected', function() { | |
console.log('disconnected'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment