Help with stupid noob sketch error please

Hi all,

I’m trying to cobble something together in a hurry using an example from FastLED and I’m missing something obvious I think.

What I want is to play a lighting pattern on a strip of 2812 LEDs when a toggle switch is either switched on or off. The state doesn’t matter. Each time it is switched, I want to display a pattern for a few seconds and then switch them all off. Next time the switch is changed, display the pattern again.

Pin 3 is driving the strip and Pin 2 is sensing the switch.

Currently, I just have a wire attached to pin2 and I’m manually touching it either to GND or 5v

What actually happens is that the pattern displays for a while and then stops mid-pattern leaving some LEDs on.

Here’s my code… What have I missed please?

#include <FastLED.h>

#define LED_PIN     3
#define NUM_LEDS    10
#define BRIGHTNESS  20
#define LED_TYPE    WS2812

int inPin = 2;         // the number of the input pin
int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin
int counter = 0;
int limit = 300;

void loop()
  reading = digitalRead(inPin);
  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
    if (reading != previous){
      previous = reading;
      counter = 0;}
      while (counter <= limit) {
        SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND;
        static uint8_t startIndex = 0;
        startIndex = startIndex + 1; /* motion speed */
        FillLEDsFromPaletteColors( startIndex);
        FastLED.delay(1000 / UPDATES_PER_SECOND);
        counter ++;

FastLED.clear() only clears the data but does not write it, unless you tell it to.
The method is defined as

void CFastLED::clear(boolean writeData = false)

Try: FastLED.clear(true);

HA! I knew it would be something stupid. Thanks