// Press the green button to fade-in,
// and the Blue button to fade out.

#include <FastLED.h>

// Pins:
#define DATA_PIN 8
#define BTN_FADE_IN 3
#define BTN_FADE_OUT 2

// How many leds in your strip?
#define NUM_LEDS 3

// Delay between each fade step
#define FADE_DELAY 10

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
  pinMode(BTN_FADE_IN, INPUT_PULLUP);
  pinMode(BTN_FADE_OUT, INPUT_PULLUP);
}

void doFade(int fade_speed) {
  static int level = 0;
  EVERY_N_MILLIS(FADE_DELAY) {
    level += fade_speed;
    if (level < 0)   level = 0;
    if (level > 255) level = 255;
    fill_solid(leds, NUM_LEDS, CHSV(255, 255, level));
    FastLED.show();
  }
}

void loop() {
  // store which direction to fade, if any
  static int fade_speed = 0;

  // Fade in
  if (!digitalRead(BTN_FADE_IN)) {
    fade_speed = 1;
  }

  // Fade out
  if (!digitalRead(BTN_FADE_OUT)) {
    fade_speed = -1;
  }

  doFade(fade_speed);
}