• Well, this thread was originally going to be a question - but I seem to have figured out how to make it work, but since I can't delete the thread, I might as well post what worked.

    I got my Kickstarter Espruinos today - my first microcontrolers , and decided trying to use them with the RGB-123 LED arrays that I also got on kickstarter. I used the 8x1 model, so I didn't have to hook up an external powersupply (see my question below) , and could run the whole thing off USB. Wired it up as was done in the example, using B15/SPI2.

    Copying the example from the video did not work - the first call to the flip() function turned all the LEDs on white at full brightness. All subsequent calls did the same. The baud rate given appears to be the problem - doubling it fixed it.

    I had success with this block of code:

    Note that all colors are BRG, not RGB!

    SPI2.setup({baud:3200000, mosi:B15});  
    var leds= Graphics.createArrayBuffer(8,1,24);
    leds.flip = function () { SPI2.send4bit(leds.buffer, 0b0001, 0b0011); } ;
    
    //at this point, you can do things like
    //leds.setColor(B,R,G) to set foreground color and the draw* methods to draw shapes. 
    
    leds.setColor(0.065,0.65,0);
    leds.drawLine(2,0,5,0);
    leds.setPixel(0,0,0xff2222);
    leds.setPixel(1,0,0xff2222);
    leds.setPixel(6,0,0xff2222);
    leds.setPixel(7,0,0xff2222);
    leds.flip();
    
    //Curiously, Graphics.setPixel(x,y) won't set that pixel to foreground color. 
    //Likewise, there aren't functions to draw shapes in a specified color - only the one set by setColor()
    //Set colors with a single function call:
    
    leds.lightPixel = function (x,y,col) {this.setPixel(x,y,col); this.flip();};
    
    leds.lightPixel(0,0,0x0011aa);
    leds.lightPixel(7,0,0x0011aa);
    

    At this point, I have a question about working with the Espruino, since I've never worked with microcontrolers before - can I safely have it connected to an external powersupply while it's connected to USB?

About

Avatar for DrAzzy @DrAzzy started