Skip to content

Instantly share code, notes, and snippets.

@creationix
Created January 21, 2021 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creationix/199da6a1d2beb22bf7de0a1a85ce2742 to your computer and use it in GitHub Desktop.
Save creationix/199da6a1d2beb22bf7de0a1a85ce2742 to your computer and use it in GitHub Desktop.
// espruino + 16 GRB Neopixels on a loop
var neopixel = require('neopixel');
var pixels = new Uint8Array(16*3);
var j = 0;
setInterval(function () {
j = (j + 17) % 768;
var o = 0;
for (var i = 0; i < 16; i++) {
var rgb = hue2rgb(i * 48 + j);
pixels[o++]=((rgb >> 8) & 0xff) >> 3;
pixels[o++]=((rgb >> 16) & 0xff) >> 3;
pixels[o++]=(rgb & 0xff) >> 3;
//pixels[o++]=(7-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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment