// Level 3: lightsaber. A button on pin 2 ignites the blade, a button on pin 3 pulls it back.
#include <Adafruit_NeoPixel.h>

const int stripPin = 6;
const int ledCount = 10;
const int igniteButtonPin = 2;
const int retractButtonPin = 3;
Adafruit_NeoPixel strip(ledCount, stripPin, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.setBrightness(40);
  strip.show();                              // start with all LEDs off
  pinMode(igniteButtonPin, INPUT_PULLUP);    // LOW when pressed
  pinMode(retractButtonPin, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(igniteButtonPin) == LOW) {
    for (int index = 0; index < ledCount; index++) {          // from the handle to the tip
      strip.setPixelColor(index, strip.Color(0, 0, 255));
      strip.show();
      delay(20);
    }
  }
  if (digitalRead(retractButtonPin) == LOW) {
    for (int index = ledCount - 1; index >= 0; index--) {     // from the tip back to the handle
      strip.setPixelColor(index, 0);
      strip.show();
      delay(20);
    }
  }
}
