// use the FastLED library (someone's pre-written code)
#include <FastLED.h>
// set how many LEDs there are and the data pin.
const int numLeds = 30;
const int ledStripPin = 6;
const int buttonPin = 2;
// this creates an array to reference our LEDs
CRGB leds[numLeds];
void setup() {
// tells the FastLED code e.g. what LEDs we are using, the data pin
FastLED.addLeds<NEOPIXEL, ledStripPin>(leds, numLeds);
// limit the strip's draw to 400mA at 5v
FastLED.setMaxPowerInVoltsAndMilliamps(5, 400);
// turns the brightness down (so my eyes don't hurt)
FastLED.setBrightness(8);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(buttonPin) == LOW){
//if button pressed
blinkLights();
} else {
turnAllOff();
}
}
void blinkLights() {
for(int i = 0; i<30; i++){
leds[i] = CRGB::Red;
}
FastLED.show();
delay(1000);
for(int i = 0; i<30; i++){
leds[i] = CRGB::Blue;
}
FastLED.show();
delay(1000);
for(int i = 0; i<30; i++){
leds[i] = CRGB::Lime;
}
FastLED.show();
delay(1000);
for(int i = 0; i<30; i++){
leds[i] = CRGB::Yellow;
}
FastLED.show();
delay(1000);
for(int i = 0; i<30; i++){
leds[i] = CRGB::Cyan;
}
FastLED.show();
delay(1000);
}
void turnAllOff() {
for(int i = 0; i<30; i++){
leds[i] = CRGB::Black;
}
FastLED.show();
}