For a temporary interface for the strip of WS2812b LEDs I use to light my bed area, I built a very simple web interface making use of the jscolor library for easy colour selection. Feel free to try it out and suggest improvements, I'm sure there are plenty to be made. Anyway here's what the interface looks like and this is the code:
var ESP8266 = require("ESP8266"),
Wifi = require("Wifi"),
curCol = '00FF00',
index = '<title>Brightness</title><script src="//cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.js"></script><form><label>Color: <input class="jscolor" value="" name="color"><br><input type="submit">',
arr = new Uint8ClampedArray(111*3);
function onPageRequest(req, res) {
var a = url.parse(req.url, true);
if(a.search !== null){
if(a.search.indexOf("color")){
curCol = a.search.split('=')[1];
updateLEDs(hexToRgb(curCol));
}
}
if(a.pathname=="/"){
res.writeHead(200, {'Content-Type': 'text/HTML'});
res.end(index.replace('value=""', 'value="' + curCol + '"'));
}else {
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end("404: Page "+a.pathname+" not found");
}
}
function hexToRgb(hex) {
var bigint = parseInt(hex, 16);
var r = (bigint >> 16) & 255;
var g = (bigint >> 8) & 255;
var b = bigint & 255;
return {"r":r, "g":g, "b":b};
}
function updateLEDs(color){
for (var i=0;i<arr.length;i+=3) {
arr[i ] = color.g;
arr[i+1] = color.r;
arr[i+2] = color.b;
}
ESP8266.neopixelWrite(NodeMCU.D1, arr);
}
function onInit(){
console.log(Wifi.getIP().ip);
require("http").createServer(onPageRequest).listen(80);
updateLEDs(hexToRgb(curCol));
}
onInit();
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
For a temporary interface for the strip of WS2812b LEDs I use to light my bed area, I built a very simple web interface making use of the jscolor library for easy colour selection. Feel free to try it out and suggest improvements, I'm sure there are plenty to be made. Anyway here's what the interface looks like and this is the code: