// 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;
// 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(2, INPUT_PULLUP);
}
void loop() {
if (digitalRead(2) == LOW) {
turnAllRainbow();
} else {
}
delay(100);
}
void turnAllRainbow() {
for (int colourNum=0; colourNum<5; colourNum++) {
for (int i=0; i<30; i++) {
if (colourNum == 0){
leds[i] = CRGB::Green;
} else if (colourNum == 1){
leds[i] = CRGB::Blue;
} else if (colourNum == 2){
leds[i] = CRGB::Red;
} else if (colourNum == 3){
leds[i] = CRGB::Purple;
} else if (colourNum == 4){
leds[i] = CRGB::White;
}
FastLED.show();
delay(100);
}
// FastLED.show();
// delay(1000);
}
}