r/FastLED • u/WebPlenty2337 • Nov 05 '23
Code_samples code check please. When i activate the button, the colour of the LEDs stay green
#include <FastLED.h>
#define NUM_LEDS 20
#define DATA_PIN 2
#define COLOUR_ORDER GRB
#define CHIPSET WS2812
#define BRIGHTNESS 50
#define VOLTS 5
#define MAX_AMPS 500
CRGB leds[NUM_LEDS];
const int buttonPin = 5; // Button pin
void setup() {
FastLED.addLeds<CHIPSET, DATA_PIN, COLOUR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear(true);
FastLED.show();
}
void loop() {
int buttonState = digitalRead(buttonPin); // Reads the state of the button
delay(10); // Debounce delay
for (int i = 0; i < NUM_LEDS; i++) {
if (buttonState == HIGH) {
leds[i] = CRGB::Red;
} else {
leds[i] = CRGB::Green;
}
}
FastLED.show();
}