Created
March 30, 2012 00:44
-
-
Save paultag/2245367 to your computer and use it in GitHub Desktop.
tri-color led wave
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 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