#include "FastLED.h"
#include "SButton.h"

// Matrix size
#define HEIGHT 16
#define WIDTH 16
#define NUM_LEDS WIDTH * HEIGHT
#define MATRIX_TYPE 1
// LEDs pin
#define DATA_PIN 3
// LED brightness
#define BRIGHTNESS 255
// Define the array of leds
CRGB leds[NUM_LEDS];
uint32_t effTimer;
bool loadingFlag = true;
uint8_t speed = 128;
uint8_t eff = 0;
bool speedDirection = 0;
byte FF[WIDTH][HEIGHT];
byte SF[WIDTH][HEIGHT];
int shift;
Sbutton btn(2, 0, 0);
void effRun() {
  if (millis() - effTimer >= 0) {
    effTimer = millis();
    switch (eff) {
      case 0: sparkles(); break;
      case 1: sand(); break;
      case 2: fire(); break;
      case 3: snow(); break;
    }
    FastLED.show();
  }
}

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
  btn.tick();
  effRun();
  if (btn.hasClicks() == 1) {
    eff++;
    loadingFlag=1;
  }
  if (btn.hasClicks() == 2) {
    eff--;
    loadingFlag=1;
  }
  if (btn.isHeld()) {
    speedDirection = !speedDirection;
  }
  if (btn.isHold()) {
    speed = constrain(speed + (speed / 25 + 1) * (speedDirection * 2 - 1), 1, 255);
  }
} //loop


uint16_t XY (uint8_t x, uint8_t y) {
  return ((HEIGHT - 1 - y) * WIDTH + x);
}