Skip to content

Instantly share code, notes, and snippets.

@paultag
Created March 30, 2012 00:44
Show Gist options
  • Save paultag/2245367 to your computer and use it in GitHub Desktop.
Save paultag/2245367 to your computer and use it in GitHub Desktop.
tri-color led wave
var Board = require('../lib/firmata').Board;
valMin = 0;
valMax = 2 * (3.141592654);
valCur = 0.0;
step = 0.1;
oscl_mult = (255/2);
leds = [ 9, 10, 11 ];
function getVals( offsetKey ) {
return [
oscl_mult * (Math.sin(valCur) + 1),
oscl_mult * (Math.cos(valCur) + 1),
oscl_mult * (Math.sin(valCur + 3.141592654) + 1)
];
}
var board = new Board('/dev/ttyUSB0', function() {
console.log("init'd");
for ( i = 0; i < leds.length; ++i ) {
board.pinMode(leds[i], board.MODES.PWM );
}
setInterval(function(){
if ( step < valMin || step > valMax ) {
step = -step;
}
valCur += step;
aoutvals = getVals(valCur);
for ( i = 0; i < leds.length; ++i ) {
board.analogWrite(leds[i], aoutvals[i]);
}
}, 50);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment