 //***************************************************************
-// Example of using an input to trigger a pixel update.
+// Example of using an input (button) to trigger an update.
+// Each press (or rather release in this case) of the button
+// updates the display, increasing the number of lit pixels. 
 //
-// A simple button is used here, but the input could be modified
-// to other types of inputs by changing the "checkInput" function
-// that monitors the input.
+// After the last pixel is lit up, the next button press resets
+// the strip (clears all pixels). Then it will start over again
+// with the next button press.
 //
 // This example uses JChristensen's Button Library from:
 //   https://github.com/JChristensen/JC_Button
 // 
+// Open serial monitor to see output progress.
 //
 // Marc Miller, Feb 2017
 //   Updated Jan 2020 - for JC_button library updates
+//   Updated May 2022 - changed myButton.wasPressed to .wasReleased to
+//                      make sure we only advace one pixel per press
 //***************************************************************
+
 
 #include "FastLED.h"
 #define DATA_PIN    11
 #define CLK_PIN     13
 #define LED_TYPE    LPD8806
 #define COLOR_ORDER GRB
-#define NUM_LEDS    32
+#define NUM_LEDS    21  // number of pixles in strip
 #define BRIGHTNESS  50
 CRGB leds[NUM_LEDS];
+
 
 // use JChristensen's Button library 
 #include "JC_Button.h"  
 const uint8_t buttonPin = 4;  // digital pin used for debounced push button
-Button myButton(buttonPin, 40, true, true);  // declare the button  (pin, dbTime, puEnable, invert)
+Button myButton(buttonPin, 100, true, true);  // declare the button  (pin, dbTime, puEnable, invert)
 
 
-uint8_t pos = NUM_LEDS-1;  // set initial position
+uint8_t pos = NUM_LEDS;  // set initial position
 boolean input = false;  // set input status
 
 

//---------------------------------------------------------------
void checkInput(){  // function to check input
  myButton.read();
  if(myButton.wasPressed() ) {
    Serial.println("Button pressed!");
    input = true;  // set input status to true
  } else {
    input = false;
  }
}//end_checkInput

  //FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);

  myButton.begin();  // initialize the button object
  startupBlink();  // blink display at startup
  Serial.println("Setup done. \n");
}


//---------------------------------------------------------------
void loop() {
  checkInput();  // calls funtion to check the input

  if (input == true) {
    pos++;  // Advance to next pixel
    if (pos > NUM_LEDS) {  // rollover back to start
      pos = 0;
      Serial.print("Position reset.  ");
    }
    if (pos == NUM_LEDS) {  // reset state reached, clear leds
      FastLED.clear();
      Serial.print("Reset, pixels cleared.  ");
    }
    else {
      if (pos == 20) {
        fill_solid(leds, NUM_LEDS, CRGB::Green);
      }
      else {
        leds[pos] = CHSV(0,255,255);  // turn on new pixel
      }
    }
    Serial.print("pos = "); Serial.println(pos);
  }

  FastLED.show();  // update the display
