#include <FastLED.h>
#define NUM_LEDS 55 // Total number of LEDs in your strip
#define DATA_PIN 3 // The Arduino pin connected to the Data In line
#define LED_TYPE WS2812B // Adjust to your specific LED type
#define COLOR_ORDER GRB // Adjust to your specific color order (may be RGB or BGR)
#define BRIGHTNESS 255 // Adjust brightness (0-255)
CRGB led[NUM_LEDS]; // create instance
#define BUTTON_PIN 2
int mode, modes = 4, currentButtonRead, lastButtonRead;
unsigned long timer, timeout = 100;
bool currentButtonState;
int leftLimb[] = { 1, 3, 6, 10, 15, 21, 28, 36, 45 };
int rightLimb[] = { 2, 5, 9, 14, 20, 27, 35, 44, 54 };
void setup() {
Serial.begin(115200);
randomSeed(analogRead(A0));
pinMode(BUTTON_PIN, INPUT_PULLUP);
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(led, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear(); // Turn all LEDs off
led[0] = CRGB(255, 255, 255);
fillTree(0, 255, 32);
FastLED.show(); // Update the strip
}
void loop() {
sparkle();
// readButton();
}
void sparkle() {
if (millis() - timer > timeout) { // event timer
timer = millis(); // reset timer
int l = random(1, NUM_LEDS); // LED. Not first LED
byte r = random(128, 255) * random(2); // red
byte g = random(128, 255) * random(2); // grn
byte b = random(128, 255) * random(2); // blu
led[l] = CRGB(r, g, b);
FastLED.show();
if (random(10)) // 9:10 chances
led[0] = CRGB(255, 255, 255); // top is usually white
else
led[0] = CRGB(0, 0, 0); // momentary black
led[l] = CRGB(0, 255, 32); // re-color tree
}
}
void limbs(byte rl, byte gl, byte bl, byte rr, byte gr, byte br) { // right and left tip colors
for (int i = 0; i < 9; i++) {
led[rightLimb[i]] = CRGB(rr, gr, br); // right limb tip pixels
led[leftLimb[i]] = CRGB(rl, gl, bl); // left limb tip pixels
FastLED.show();
}
}
void fillTree(byte r, byte g, byte b) { // tree color
for (int i = 1; i < NUM_LEDS; i++) {
led[i] = CRGB(r, g, b);
}
}
void readButton() {
bool currentButtonRead = digitalRead(BUTTON_PIN); // read button pin
if (currentButtonRead != lastButtonRead) { // if button pin changes...
timer = millis(); // ...start a timer
lastButtonRead = currentButtonRead; // ... and store current state
}
if ((millis() - timer) > timeout) { // if button change was longer than debounce timeout
if (currentButtonState == HIGH && lastButtonRead == LOW) { // ... and State is "RELEASED" while Button Read is "PRESSED"
mode++; // advance the mode
if (mode > modes) // constrain the mode
mode = 0; // reset mode count
currentButtonState = currentButtonRead; // update button state
}
}
}1000uf
electrolytic
capacitor