diff --git a/include/config.sample.h b/include/config.sample.h index 500f248..5075afb 100644 --- a/include/config.sample.h +++ b/include/config.sample.h @@ -21,10 +21,15 @@ #define SPEEDUP 1 #define MAX_MILLIAMPS 1000 +// Maximum color difference for the random effects. +// This changes the hue value +/- this value. Use a maximum value of 127, otherwise strange things might happen. +#define COLOR_DIFFERENCE 25 #define WIFI_SSID "..." #define WIFI_PASS "..." +#define OTA_HOSTNAME "..." + #define MQTT_CLIENT_ID "espleaf" #define MQTT_USER "..." #define MQTT_PASS "..." diff --git a/src/main.cpp b/src/main.cpp index e7b1d87..086ad51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,11 +220,9 @@ void loop() { } if (random8(128)==0) { - if (active_mode == AM_FIRST_CORNER) { - corners[0]->blend_to(CHSV(random8(), 255, 255)); - } else { - corners[random16(corners.size())]->blend_to(CHSV(random8(), 255, 255)); - } + uint16_t corner = (active_mode == AM_FIRST_CORNER) ? 0 : random16(corners.size()); + CHSV color = rgb2hsv_approximate(corners[corner]->color); + corners[corner]->blend_to(CHSV(color.h - COLOR_DIFFERENCE + random8(2*COLOR_DIFFERENCE), 255, 255)); } } else if (active_mode == AM_NODES || active_mode == AM_FIRST_NODE) { for(Node* node : nodes) { @@ -233,11 +231,9 @@ void loop() { } if (random8(128)==0) { - if (active_mode == AM_FIRST_NODE) { - nodes[0]->blend_to(CHSV(random8(), 255, 255)); - } else { - nodes[random8(nodes.size())]->blend_to(CHSV(random8(), 255, 255)); - } + uint16_t corner = (active_mode == AM_FIRST_NODE) ? 0 : random8(nodes.size()); + CHSV color = rgb2hsv_approximate(corners[corner]->color); + nodes[corner]->blend_to(CHSV(color.h - COLOR_DIFFERENCE + random8(2*COLOR_DIFFERENCE), 255, 255)); } } else if (active_mode == AM_FLASH) { for (Node* node : nodes) {