Created
January 21, 2021 21:39
-
-
Save creationix/199da6a1d2beb22bf7de0a1a85ce2742 to your computer and use it in GitHub Desktop.
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
// 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