Last active
December 15, 2025 19:47
-
-
Save LenweSaralonde/3ded8133064a41106923e75b11ee9269 to your computer and use it in GitHub Desktop.
Sakura cherry blossom ARGB effect for Arduino board
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Sakura cherry blossom ARGB effect | |
| // Requires the FastLED library | |
| // Connect digital pin 2 to your ARGB controller with a 470 Ohm resistor in series. | |
| // Connect PC case LED button to digital pin 3 to control brightness ofer 5 levels (saved after power down). | |
| #include <FastLED.h> | |
| #include <EEPROM.h> | |
| #define NUM_LEDS 8 | |
| #define DATA_PIN 2 | |
| #define BUTTON_PIN 3 | |
| #define FPS 1000 | |
| #define FADE_STEP 0.003 | |
| #define LED_TYPE WS2812B | |
| #define LED_CORRECTION 0xFFD750 // Mars Gaming MF-3D | |
| #define COLOR_ORDER GRB | |
| #define EEPROM_BRIGHTNESS_ADDR 0 | |
| CRGB leds[NUM_LEDS]; | |
| CRGB colors[NUM_LEDS + 1]; | |
| const uint8_t brightnessLevels[] = { 255, 0, 51, 102, 153, 204 }; // Corresponds to 100%, OFF, 20%, 40%, ... | |
| uint8_t brightnessIndex = 0; // 100% initially | |
| bool lastButtonState = HIGH; | |
| int colorIndex; | |
| float colorPosition; | |
| float frameDelay = 1000 / FPS; | |
| CRGB generateBlossomColor() { | |
| byte hue = random(220, 256); // pink-red hue range | |
| byte sat = random(50, 130); // pastel saturation | |
| byte val = random(200, 255); // soft brightness | |
| return CHSV(hue, sat, val); | |
| } | |
| void initColors() { | |
| colorIndex = 0; | |
| colorPosition = 0; | |
| for (int i = 0; i < NUM_LEDS + 1; i++) { | |
| colors[i] = CRGB::Black; | |
| } | |
| } | |
| void setup() { | |
| // Read saved brightness index from EEPROM | |
| brightnessIndex = EEPROM.read(EEPROM_BRIGHTNESS_ADDR); | |
| if (brightnessIndex >= sizeof(brightnessLevels)) { // EEPROM is initialized with 255 which is off bounds | |
| brightnessIndex = 0; | |
| } | |
| // Initialize PINS and built-in LED | |
| pinMode(BUTTON_PIN, INPUT_PULLUP); | |
| pinMode(LED_BUILTIN, OUTPUT); | |
| // Initialize ARGB LEDs | |
| FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); | |
| FastLED.setBrightness(brightnessLevels[brightnessIndex]); | |
| FastLED.setCorrection(LED_CORRECTION); | |
| FastLED.clear(); | |
| FastLED.show(); | |
| initColors(); | |
| } | |
| void loop() { | |
| // Handle brightness button | |
| bool currentButtonState = digitalRead(BUTTON_PIN); | |
| if (currentButtonState != lastButtonState) { | |
| digitalWrite(LED_BUILTIN, currentButtonState ? LOW : HIGH); // Blink built-in LED when button is pressed | |
| if (lastButtonState == HIGH && currentButtonState == LOW) { | |
| brightnessIndex = (brightnessIndex + 1) % (sizeof(brightnessLevels)); | |
| FastLED.setBrightness(brightnessLevels[brightnessIndex]); | |
| EEPROM.update(EEPROM_BRIGHTNESS_ADDR, brightnessIndex); | |
| } | |
| } | |
| lastButtonState = currentButtonState; | |
| // Assign colors to LEDs | |
| for (int i = 0; i < NUM_LEDS; i++) { | |
| CRGB color1 = colors[(i + colorIndex) % (NUM_LEDS + 1)]; | |
| CRGB color2 = colors[(i + colorIndex + 1) % (NUM_LEDS + 1)]; | |
| leds[i] = color1 % (255 * (1 - colorPosition)) + color2 % (255 * colorPosition); | |
| } | |
| // Color shifting animation | |
| colorPosition += FADE_STEP; | |
| if (colorPosition >= 1) { | |
| colors[colorIndex] = generateBlossomColor(); | |
| colorPosition = 0; | |
| colorIndex = (colorIndex + 1) % (NUM_LEDS + 1); | |
| } | |
| // Refresh LEDs | |
| FastLED.show(); | |
| // Main delay | |
| delay(frameDelay); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Schematics for connecting the Arduino Nano Every into the PC and the ARGB fans
The Arduino can be powered in 5V by an IDE Molex connector, SATA connector or by USB.
The pinout of your ARGB connector may be different. The ARGB +5V might not be needed if you have an ARGB hub.