// https://www.reddit.com/r/FastLED/comments/1etf7dk/fill_gradient_flickers_a_ton_on_3k_leds_teensy_41/

#include <FastLED.h>
#include "fill_gradient2.h"

#define NUM_LEDS_STRIP 248
#define NUM_PINS 8
#define NUM_LEDS_TABLE NUM_LEDS_STRIP*NUM_PINS // 2976

typedef struct fillgrad {
  uint8_t one;
  uint8_t two;
  uint8_t three;
  uint8_t four;
  uint8_t five;
  uint8_t six;
} fillgrad_t;

fillgrad_t fg;

CRGB leds[NUM_LEDS_TABLE];

void setup() {
  FastLED.addLeds<WS2812B, 25, GRB>(leds, 0, 248);
  FastLED.addLeds<WS2812B, 22, GRB>(leds, 248 * 7, 248);
  Serial.begin(115200);
}


void loop() {
  mode_fillgrad();
  FastLED.show();
  int test_led = 0;
  test_led = NUM_LEDS_TABLE - 1;
  Serial.print(leds[test_led].r);
  Serial.print(",");
  Serial.print(leds[test_led].g);
  Serial.print(",");
  Serial.println(leds[test_led].b);
  delay(20);
}

void fillgrad_random() {
  fg.one = random8(1, 25);
  fg.two = random8(0, 10);
  fg.three = random8(200, 255);
  fg.four = random8(1, 25);
  fg.five = random8(0, 10);
  fg.six = random8(200, 255);
}

void fill_grad() {
  uint8_t starthue = beatsin8(fg.one, fg.two, fg.three);
  uint8_t endhue = beatsin8(fg.four, fg.five, fg.six);

  if (starthue < endhue) {
    fill_gradient(leds, NUM_LEDS_TABLE, CHSV(starthue, 255, 255), CHSV(endhue, 255, 255), FORWARD_HUES);
  } else {
    fill_gradient(leds, NUM_LEDS_TABLE, CHSV(starthue, 255, 255), CHSV(endhue, 255, 255), BACKWARD_HUES);
  }

  EVERY_N_SECONDS(5) {
    fillgrad_random();
  }
}

void mode_fillgrad() {
  EVERY_N_MILLIS(10) {
    fill_grad();
  }
}