Created
December 20, 2015 16:04
-
-
Save jnovack/095e86bc04b1d02feee2 to your computer and use it in GitHub Desktop.
Old LED functions
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
function flash() { | |
var num = Math.floor(Math.random()*25); | |
if (num === 1) { | |
driver.setRGB('#FFFFFF', 0, 1, 2); | |
} else { | |
driver.setRGB('#000000', 0, 1, 2); | |
} | |
driver.send(); | |
setTimeout(function() { flash() }, 10); | |
}; | |
// ------------------------------------ | |
var Chromath = require('chromath') | |
var it = true; | |
var colors = Chromath.gradient('red', 'blue', 60).toString().split(','); | |
function cross(colors, delay) { | |
var color = colors.shift(); | |
if (typeof color !== 'undefined') { | |
driver.setRGB(color, 0, 1, 2); | |
driver.send(); | |
setTimeout(function() { cross(colors, delay)}, delay); | |
} else { | |
if (it === false) { process.exit(); } | |
it = false; | |
var colors = Chromath.gradient('blue', 'red', 60).toString().split(','); | |
setTimeout(function() { cross(colors, delay)}, delay); | |
} | |
}; | |
// ------------------------------- | |
var step = 0.025; | |
function fade(color, direction, delay) { | |
driver.pset(0, color); | |
driver.pset(1, color); | |
driver.pset(2, color); | |
driver.send(); | |
direction ? color += step : color -= step; | |
if (color <= 0 || color >= 1) { direction = !direction; } | |
setTimeout(function() { fade(color, direction, 1)}, delay); | |
}; | |
// ---------------------------------- | |
var step = 0.025; | |
(function pulse(color, direction, delay) { | |
driver.pset(9, color); | |
driver.pset(10, color); | |
driver.pset(11, color); | |
driver.send(); | |
direction ? color += step : color -= step; | |
if (color <= 0 || color >= 1) { direction = !direction; } | |
process.stdout.write(" " + Math.floor(color*255).toString() + " \r"); | |
setTimeout(function() { fade(color, direction, delay)}, delay); | |
})(0, true, 100); | |
// -------------------------------------- | |
colors = [ | |
'#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', | |
'#FF00FF', '#FFFFFF', '#FFA500', '#9B30FF', '#F660AB' | |
]; | |
(function sparkle(colors) { | |
var num = Math.floor((Math.random()*colors.length)); | |
driver.setRGB(colors[num], 0, 1, 2); | |
driver.send(); | |
setTimeout(function() { sparkle(colors) }, 10); | |
})(colors); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment