Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var pin = D14;
var esp = require('ESP8266');
function write(data) {
esp.neopixelWrite(D14, data);
}
var count = 16+16+7+64;
var pixels = new Uint8Array(count * 3);
function wheel(h){
var r, g, b;
h = h % 768;
if (h < 256) {
r = h;
g = 255 - h;
b = 0;
} else if (h < 512) {
r = 511 - h;
g = 0;
b = h - 256;
} else {
r = 0;
g = h - 512;
b = 767 - h;
}
return [r, g, b];
}
var x =0;
var hh = 0;
var total = count * 3;
var offset = (count >> 3);
var coffset = (768 >> 3);
var ratio = Math.floor(768 / count);
setInterval(function () {
/*
hh = (hh + 20) % 768;
for (var i = 0; i < count; i += 1) {
var h = (hh + (i << 3)) % 768;
var g, r, b;
if (h < 256) {
g = 255 - h;
r = h;
b = 0;
} else if (h < 512) {
g = 0;
r = 511 - h;
b = h - 256;
} else {
g = h - 512;
r = 0;
b = 767 - h;
}
var k = i * 3;
pixels[k] = g >> 4;
pixels[k + 1] = r >> 4;
pixels[k + 2] = b >> 4;
}
*/
hh = (hh + 1) % 768;
x = (x + 1) % count;
for (var j = 2; j <= 8; j++) {
for (var n = 0; n < 8; n++) {
var k = ((8-j+x+n*offset) * 3) % total;
var color = wheel(hh + n * coffset);
pixels[k + 1] = color[0] >> j;
pixels[k] = color[1] >> j;
pixels[k + 2] = color[2] >> j;
}
}
write(pixels);
}, 33);
save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment