From 7651e46ee066c42beec415bfa42bdbcd2ebaa081 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Sun, 10 Jan 2021 16:27:49 +0100 Subject: [PATCH] Speed can now be changed on-the-fly by setting `speedup`. --- include/prototypes.h | 1 + src/main.cpp | 3 ++- src/mqtt.cpp | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/prototypes.h b/include/prototypes.h index a579499..de7d6f1 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -32,3 +32,4 @@ extern AnimationMode mode; extern AnimationMode temp_mode; extern unsigned long temp_mode_until; extern int return_to_brightness; +extern uint8_t speedup; diff --git a/src/main.cpp b/src/main.cpp index 850ce9a..563d930 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ AnimationMode mode = AM_CORNERS; AnimationMode temp_mode; unsigned long temp_mode_until; int return_to_brightness = -1; +uint8_t speedup = SPEEDUP; unsigned long last_loop = 0; @@ -156,7 +157,7 @@ void loop() { mqtt_loop(); ArduinoOTA.handle(); - EVERY_N_MILLISECONDS(20 / SPEEDUP) { + if (speedup > 0 && (millis() - last_loop > (20 / speedup) || last_loop > millis())) { looping = false; AnimationMode active_mode = mode; diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 9cb7e5d..31b589e 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -67,6 +67,8 @@ void callback(char* topic, byte* pl, unsigned int length) { else if (value.equals("yellow")) { color = CRGB::Yellow; } else if (value.equals("orange")) { color = CRGB::Orange; } else { LOGln("Unknown color name %s.", value.c_str());} + } else if (key.equals("speedup")) { + speedup = value.toInt(); } else { LOGln("Unknown key '%s'. (For reference: Value is '%s'.)", key.c_str(), value.c_str()); }