diff --git a/usermods/usermod_v2_KITT/README.md b/usermods/usermod_v2_KITT/README.md new file mode 100644 index 0000000000..dcb3af88d4 --- /dev/null +++ b/usermods/usermod_v2_KITT/README.md @@ -0,0 +1,8 @@ +# KITT Usermod Effect + +v2 usermod for replicating the effect found on KITT, the car from the 80's TV show Knightrider. +The original effect was in Red, however, the usermod also supports palettes + +## Include the usermod + +* `-D USERMOD_KITT` diff --git a/usermods/usermod_v2_KITT/usermod_v2_KITT.h b/usermods/usermod_v2_KITT/usermod_v2_KITT.h new file mode 100644 index 0000000000..833fb0986e --- /dev/null +++ b/usermods/usermod_v2_KITT/usermod_v2_KITT.h @@ -0,0 +1,69 @@ +#pragma once +#include "wled.h" + +#ifndef FX_MODE_KITT +#define FX_MODE_KITT 255 // Auto-allocate number +#endif + +class KITTUsermod : public Usermod { + private: + // strings to reduce flash memory usage (used more than twice) + static const char _FX_MODE_KITT[]; + + /* + * Uses speed, intensity (tail), custom1 (delay) and option1 checkbox for dual mode + */ + static uint16_t mode_kitt(void) { + if (SEGLEN == 1) { + SEGMENT.fill(SEGCOLOR(0)); + return FRAMETIME; + } + if (SEGMENT.call == 0) { + SEGMENT.aux0 = 0; + SEGMENT.step = 0; + } + SEGMENT.fade_out(255 - SEGMENT.intensity); // Fade to SEGCOLOR(1) - BG + if (SEGMENT.step > millis()) + return FRAMETIME; // delay hasn't finished yet + else + SEGMENT.step = 0; + + // delay before move + if (SEGMENT.call % (((255 - SEGMENT.speed) >> 4) + 1) == 0) { + if (SEGMENT.aux0 < 2*SEGLEN) { + uint16_t pos = (SEGMENT.aux0 / SEGLEN) & 0x1 ? + SEGLEN - 1 - (SEGMENT.aux0 % SEGLEN) : // odd down + SEGMENT.aux0 % SEGLEN; // even up + uint32_t color1 = SEGMENT.color_from_palette(pos, true, false, 0); + SEGMENT.setPixelColor(pos, color1); + if (SEGMENT.check1) { // dual + SEGMENT.setPixelColor(SEGLEN - 1 - pos, color1); + } + SEGMENT.aux0++; + } else { + SEGMENT.step = millis() + SEGMENT.custom1 * 10; // multiply by 10ms + SEGMENT.aux0 = 0; // wrap after delay + } + } + return FRAMETIME; + } + + public: + // gets called once at boot. + // parameters are already read by readFromConfig, busses & segments have been created by beginStrip() + void setup() { + strip.addEffect(FX_MODE_KITT, &mode_kitt, _FX_MODE_KITT); + } + void loop() {} // must be overridden + /* + * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!). + * This could be used in the future for the system to determine whether your usermod is installed. + */ + uint16_t getId() { + return USERMOD_ID_KITT; + } +}; + +// config strings to reduce flash memory usage (used more than twice) +// (Speed & Fade & Dual checkbox);(2 Colours, Fg & Bg);(Enabled);(1Dim); +const char KITTUsermod::_FX_MODE_KITT[] PROGMEM = "KITT@!,Tail,Delay,,,Dual;!,!;!;1;sx=210"; diff --git a/wled00/const.h b/wled00/const.h index 3f4ef5cfc1..4981b43795 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -151,6 +151,7 @@ #define USERMOD_ID_WIREGUARD 41 //Usermod "wireguard.h" #define USERMOD_ID_INTERNAL_TEMPERATURE 42 //Usermod "usermod_internal_temperature.h" #define USERMOD_ID_LDR_DUSK_DAWN 43 //Usermod "usermod_LDR_Dusk_Dawn_v2.h" +#define USERMOD_ID_KITT 45 //Usermod "usermod_v2_KITT.h" //Access point behavior #define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot diff --git a/wled00/usermods_list.cpp b/wled00/usermods_list.cpp index e5f9c28415..30693a38eb 100644 --- a/wled00/usermods_list.cpp +++ b/wled00/usermods_list.cpp @@ -201,6 +201,11 @@ #include "../usermods/LDR_Dusk_Dawn_v2/usermod_LDR_Dusk_Dawn_v2.h" #endif +#ifdef USERMOD_KITT + #include "../usermods/usermod_v2_KITT/usermod_v2_KITT.h" +#endif + + void registerUsermods() { /* @@ -380,4 +385,8 @@ void registerUsermods() #ifdef USERMOD_LDR_DUSK_DAWN usermods.add(new LDR_Dusk_Dawn_v2()); #endif + + #ifdef USERMOD_KITT + usermods.add(new KITTUsermod()); + #endif }