#include #include #define BUTTON_PIN 0 #define STATUS_LED_PIN 1 #define NUM_LEDS 8 #define LED_TYPE WS2812B #define COLOR_ORDER GRB #define BRIGHTNESS 80 CRGB leds[NUM_LEDS]; unsigned long lastBlinkTime = 0; bool statusLedState = false; uint8_t colorMode = 0; // 0 = red, 1 = green, 2 = blue void blinkStatusLedThreeTimes() { for (int i = 0; i < 3; i++) { digitalWrite(STATUS_LED_PIN, HIGH); delay(120); digitalWrite(STATUS_LED_PIN, LOW); delay(120); } } void setEighthLedColor() { fill_solid(leds, NUM_LEDS, CRGB::Black); if (colorMode == 0) { leds[7] = CRGB::Red; } else if (colorMode == 1) { leds[7] = CRGB::Green; } else { leds[7] = CRGB::Blue; } FastLED.show(); colorMode++; if (colorMode > 2) { colorMode = 0; } } void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); pinMode(STATUS_LED_PIN, OUTPUT); FastLED.setBrightness(BRIGHTNESS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); FastLED.addLeds(leds, NUM_LEDS); fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); } void loop() { if (digitalRead(BUTTON_PIN) == LOW) { delay(30); if (digitalRead(BUTTON_PIN) == LOW) { setEighthLedColor(); blinkStatusLedThreeTimes(); while (digitalRead(BUTTON_PIN) == LOW) { delay(10); } delay(30); } } if (millis() - lastBlinkTime >= 1000) { lastBlinkTime = millis(); statusLedState = !statusLedState; digitalWrite(STATUS_LED_PIN, statusLedState); } }