/*
  Testing FastLED with ATTinyCore
*/

#define FASTLED_INTERNAL
#include <FastLED.h>

#define LED_PIN     PB4 // Change to Pin PB4 for Franzininho DIY
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    64
#define BRIGHTNESS  255

CRGB leds[NUM_LEDS];

uint8_t gHue = 0;       // Used to cycle through rainbow
uint8_t moveSpeed = 6;  // Higher value moves pixel faster
uint8_t fadeRate = 80;  // Use lower value to give a fading tail

void setup() {
  // Setup the neopixel
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

//---------------------------------------------------------------
void loop() {
  EVERY_N_MILLISECONDS(10) {
    gHue++;             // Slowly cycle through the rainbow
  }
  beat8_tail();         // Subroutine to move the pixel!
  FastLED.show();       // Display the pixels
}

void beat8_tail() {
  EVERY_N_MILLISECONDS(5) {
    fadeToBlackBy(leds, NUM_LEDS, fadeRate);   // Fade out pixels
  }
  uint16_t pos = beat8(moveSpeed) % NUM_LEDS;  // Modulo the position to be within NUM_LEDS
  leds[pos] = CHSV(gHue, 200, 255);
}