-
• #2
Also, as a sidenote, maybe my light string is funny, but even the regular functional form doesn't seem to work right:
SPI2.setup({baud:3200000, mosi:B15}); SPI2.send4bit([255,0,0, 0,255,0, 0,0,255], 0b0001, 0b0011);
It lights up the first LED in a single color or not at all, and that's it.
This is probably related to baude, but maybe should be noted here.
Update: I spoke too soon. I updated the firmware, and it worked like a charm.
SPI2.setup({baud:3200000, mosi:B15}); SPI2.send4bit([255,0,0, 0,255,0, 0,0,255], 1, 3);
sets LEDs 1, 2, &3 to red, green, blue.
Update 2: It seems my code works great after the update, in it's original form. here is the complete lib,if anybody is interested:
/** * Simple WS2811 interface * @param {Number} interval (100) Milliseconds for update interval * @param {Number} len (50) length of light-string * @param {Number} baud (3200000) bauderate of SPI * @param {Pin} pin (B15) data-pin */ function WS2811(interval, len, baud, pin){ var self = this; self.interval = interval ||100; self.len = len || 50; self.leds = new Uint8Array(self.len * 3); SPI2.setup({baud:baud || 3200000, mosi:pin || B15}); self.reset(); // update at interval to copy vals to pixel array self.interval = setInterval(function(){ self.setArray(self.leds); }, self.interval); } /** * Set all pixels to black */ WS2811.prototype.reset = function(){ this.leds = this.leds.map(function(){ return 0; }); }; /** * Send array in pixel-friendly format * @param {Array} data the pixels in R,G,B,R,G,B,... format */ WS2811.prototype.setArray = function(data){ SPI2.send4bit(data, 1,3); }; /** * Set a pixel to an RGB value * @param {Number} i The pixel ID * @param {Array} color An RGB color, 0-255, in array */ WS2811.prototype.setRGB = function(i, color){ this.leds[i*3 ] = color[0]; this.leds[i*3 + 1] = color[1]; this.leds[i*3 + 2] = color[2]; }; // USAGE var lights = new WS2811(); // scroll all pixels through white colors function whiteScroll(){ var pos = 0; setInterval(function(){ pos++; for (var i=0; i<lights.leds.length; i+=3){ var col = (Math.sin(i+pos*0.2)+1) * 127; lights.setRGB(i/3, [col,col,col]); } }, 100); } // blink red, green,blue for pixels 1,2,3 to tell us we are starting // then, run our sequence function lights.setRGB(0, [255,0,0]); lights.setRGB(1, [0,255,0]); lights.setRGB(2, [0,0,255]); setTimeout(function(){ lights.reset(); whiteScroll(); }, 100);
-
• #3
Great, thanks for the update!
Unfortunately most of the rev 1.3 boards ship with firmware that's 6 months old now, and we've fixed and added a massive amount since then!
Out of interest, why didn't you update when you first got the board? Just wondering whether I could have made it more obvious in the Web IDE - obviously it sucks if people's first impressions of Espruino are of something that doesn't quite work correctly! :)
-
• #4
It was pretty obvious, once I read the docs. I just now had some time to play with it, and pulled it out of a drawer. No fault of the docs, I should have done this, right away. Very impressed. Super-easy to get started.
-
• #5
As a complete sidenote, I have a lot of experience with native javascript apps. If you guys are interested, I'd be happy to work on a port of the app to a node-webkit standalone. The benefits would be native file access (save files with actual save-file dialog) and no need for chrome install. Is the chrome-only stuff pretty well separated?
-
• #6
@mattbrailsford actually started off with a node-webkit app IIRC. If you've got time it'd be very handy as a way to reduce dependency on Chrome's web store (and Google Logins) - especially if the same code + repo could be used for both Chrome and node-webkit.
Also, an Android port would be epic. It looks like it might be coming to node-webkit soon...
The Web IDE code is at http://www.github.com/espruino/EspruinoWebIDE
It should be relatively well separated now - you'd just need to make a new version of Espruino.Core.Serial that used node-serial for comms, and maybe add some abstraction for load/save file and chrome's configuration stuff.
My ultimate goal would be to allow the Web IDE to be served up from the SD card by Espruino itself :) any changes to make the IDE less dependent on Chrome would really help with that.
I am pretty used to Javascript OOP prototypical programming, but am brand new to Espruino & having some issues. I am making a WS2811 lib, to get my feet wet with Espruino.
I get this:
ERROR: Constructor should be a function at line 1 col 6.
If I change the constructor to another form:
I get:
ERROR: Function not found! Skipping. at line 1 col 13
What am I doing wrong?