You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • It's probably that the data is getting sent out too slowly so the lights think its the start of a frame - in Espruino you can just supply the whole array of data at once, like this:

    SPI2.setup({mosi:B15, sck:B13, baud:4000000});
    var NumLEDs = 150;
    var leds = new Uint8Array(8 + NumLEDs*4);
    function draw() {
      var millis = getTime();
      var r = Math.random()*255;
      var g = Math.random()*255;
      var b = Math.random()*255;
      for (var pixel = 4; pixel < leds.length-4; pixel+=4)
      {
        leds[pixel+0] = 0xE0 | 5;
        leds[pixel+1] = b;
        leds[pixel+2] = g;
        leds[pixel+3] = r;
      }
      write_leds(leds, NumLEDs);
    }
    
    function write_leds(leds, numLeds) {
      // set start frame
      leds[0] = 0;
      leds[1] = 0;
      leds[2] = 0;
      leds[3] = 0;
      // set end frame
      leds[leds.length-4] = 0xff;
      leds[leds.length-3] = 0xff;
      leds[leds.length-2] = 0xff;
      leds[leds.length-1] = 0xff;
      // Send the data
      SPI2.write(leds);
    } // write_leds()
    
    function onInit() {
      setInterval(draw, 50);
    }
    onInit();
    

    You can use ArrayBufferViews so that you can get a 0-based index for the LEDs, but for now it's probably simpler to just use the single array, and start your LED indices from 4.

About

Avatar for Gordon @Gordon started