wood tree final version

This commit is contained in:
Neale Pickett 2020-12-19 20:20:49 -07:00
parent 087e90e0c1
commit 5b90bb5004
1 changed files with 27 additions and 26 deletions

View File

@ -9,10 +9,10 @@
#define FLASH_EEPROM true #define FLASH_EEPROM true
#endif #endif
//#define DEBUG #define DEBUG
// Which pins your NeoPixels are connected to // Which pins your NeoPixels are connected to
#define LEDS_PIN 4 #define LEDS_PIN 2
// How many LEDS you have. 24 for xmas advent, 9 for menorah, etc. // How many LEDS you have. 24 for xmas advent, 9 for menorah, etc.
#define NUM_LEDS 24 #define NUM_LEDS 24
@ -31,31 +31,29 @@
#define STAR_COLOR CHSV(24, 150, 255) #define STAR_COLOR CHSV(24, 150, 255)
// These colors mirror pretty closely some cheapo LED lights we have uint8_t RandomHue() {
const uint32_t colors[] = { switch (random(12)) {
0xdd4400, // Yellow case 0 ... 2:
0xff0000, // Red return 52; // reddish yellow
0xdd2200, // Amber case 3 ... 5:
0x004400, // Green return HUE_RED;
case 6 ... 8:
0xdd4400, // Yellow return 28; // reddish orange
0xff0000, // Red case 9:
0xdd2200, // Amber return HUE_BLUE;
0x880044, // Purple case 10:
return HUE_GREEN;
0xdd4400, // Yellow case 11:
0xff0000, // Red return 204; // reddish purple
0xdd2200, // Amber }
0x000088, // Blue }
};
const int ncolors = sizeof(colors) / sizeof(*colors);
CRGB leds[NUM_LEDS]; CRGB leds[NUM_LEDS];
int lastLightOn; int lastLightOn;
void setup() { void setup() {
FastLED.addLeds<WS2812B, LEDS_PIN, RGB>(leds, NUM_LEDS); FastLED.addLeds<WS2812B, LEDS_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(128); FastLED.setBrightness(64);
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
@ -87,15 +85,18 @@ bool strandUpdate() {
int twinkler = random(lastLightOn + 1); int twinkler = random(lastLightOn + 1);
// Make sure it's got the right things on and off // Make sure it's got the right things on and off
for (int pos = 0; pos < NUM_LEDS; ++pos) { for (int pos = 0; pos < NUM_LEDS; ++pos) {
uint32_t color = colors[random(ncolors)]; uint8_t hue = RandomHue();
uint8_t saturation = 255;
uint8_t value = 255;
if (pos <= lastLightOn) { if (pos <= lastLightOn) {
if (pos == THE_WHITE_ONE) { if (pos == THE_WHITE_ONE) {
leds[pos] = STAR_COLOR; saturation = 30;
} else if ((pos == twinkler) || !(leds[pos])) {
leds[pos] = color;
if ((random(100) > ACTIVITY) && (pos != lastLightOn)) {
leds[pos].fadeLightBy(180);
} }
if ((pos == twinkler) || !(leds[pos])) {
if ((random(100) > ACTIVITY) && (pos != lastLightOn)) {
value = 100;
}
leds[pos] = CHSV(hue, saturation, value);
} }
} else { } else {
leds[pos] = 0; leds[pos] = 0;