#include <FastLED.h>
#define LED_PIN 2
#define LED_COUNT 48
CRGB leds[LED_COUNT];
#define BUTTON_1 3
#define BUTTON_2 4
#define BUTTON_3 5
#define BUTTON_4 6 // random number, may want to pick a better pin if needed
CRGB currentColor = CRGB::Black;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, LED_COUNT);
FastLED.setBrightness(255);
pinMode(BUTTON_1, INPUT_PULLUP);
pinMode(BUTTON_2, INPUT_PULLUP);
pinMode(BUTTON_3, INPUT_PULLUP);
// steps to setup the Interrupt for BUTTON_4
pinMode(BUTTON_4, INPUT_PULLUP); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (BUTTON_4), changeEffect, CHANGE);
// start with all LEDs black
fill_solid(leds, LED_COUNT, CRGB::Black); // FastLED build-in function
FastLED.show();
}
void loop() {
// you could do something here or do a tiny delay here or nothing at all
}
void changeEffect(){
bool button1 = digitalRead(BUTTON_1) == LOW;
bool button2 = digitalRead(BUTTON_2) == LOW;
bool button3 = digitalRead(BUTTON_3) == LOW;
if (button1 && button2) {
currentColor = CRGB::Red;
} else if (button1 && button3) {
currentColor = CRGB::Yellow;
} else if (button2 && button3) {
currentColor = CRGB::Blue;
} else if (button1) {
currentColor = CRGB::Green;
} else if (button2) {
currentColor = CRGB::Pink;
} else if (button3) {
currentColor = CRGB::White;
} else {
currentColor = CRGB::Black;
}
fill_solid(leds, LED_COUNT, currentColor);
FastLED.show();
}