#include <FastLED.h>

CRGBArray<256> leds;

void setup() {
  FastLED.addLeds<WS2812B, 2, GRB>(leds, leds.size());
  Serial.begin(2000000);
}

uint32_t seed = 0x5eed517;
void loop() {
  static uint32_t us_total = 0;
  const auto fades = 128; // number of simultaneous fades
  const uint8_t microsteps = 256 / fades > 0 ? 256 / fades : 1;
  for (uint8_t ov8 = 0; ov8 < microsteps; ov8++) {
    uint32_t us1 = micros();
    uint16_t v16 = ov8 << 8; // accumulator for Value/Brightness
    for (auto i = 0; i < fades; i++) {
      uint16_t rnd = hash16();
      uint8_t ledno = (rnd ^ (rnd >> 8)) % leds.size();
      rnd = hash16();
      uint8_t h = rnd >> 8;
      uint8_t s = rnd;
      uint8_t v = v16 >> 8;
      v16 += 65536 / fades;
      // if (i == fades - 2) Serial.println(v);
      if (v < 128) v *= 2; // fade out
      else v = 255 - 2 * v; // fade in
      leds[ledno] += CHSV(h, s, v);
    }
    us_total += micros() - us1;
    seed -= 0x2a08c07 * 2 * fades; // rewind PRNG
    FastLED.show();
    FastLED.clear();
  }
  seed += 0x2a08c07 * 2; // advance PRNG by two steps, to advance 1 fade
  static uint8_t us_ticks = 0;
  if ( ! ++us_ticks) {
    Serial.print(FastLED.getFPS()); Serial.print("\t");
    Serial.print(float(us_total) / fades / 256 / microsteps);
    Serial.println("μs");
    us_total = 0;
  }
}

// a simple 16-bit PRNG using a 32-bit seed
uint16_t hash16() {
  seed += 0x2a08c07;
  return (seed >> 16) ^ (uint16_t)seed;
}
FPS: 0
Power: 0.00W