Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active January 21, 2021 20:48
Show Gist options
  • Save creationix/c6bead02482146af234c9ba908f5eba8 to your computer and use it in GitHub Desktop.
Save creationix/c6bead02482146af234c9ba908f5eba8 to your computer and use it in GitHub Desktop.
// espruino + 8 GRBW Neopixels on a stick
var neopixel = require('neopixel');
var pixels = new Uint8Array(8*4+1);
var j = 0;
setInterval(function () {
j = (j + 17) % 768;
var o = 0;
for (var i = 0; i < 8; i++) {
var rgb = hue2rgb(i * 13 + j);
pixels[o++]=((rgb >> 8) & 0xff) >> 3;
pixels[o++]=((rgb >> 16) & 0xff) >> 3;
pixels[o++]=(rgb & 0xff) >> 3;
pixels[o++]=i;
}
neopixel.write(D4,pixels);
}, 66);
function hue2rgb(h) {
h = h % 768;
return h < 256 ? (((255 - h) << 16) | (h << 8)) :
h < 512 ? (((511 - h) << 8) | (h - 256)) :
((767 - h) | ((h - 512) << 16));
}
@creationix
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment