Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: KITT usermod effect #3756

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions usermods/usermod_v2_KITT/README.md
Original file line number Diff line number Diff line change
@@ -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`
69 changes: 69 additions & 0 deletions usermods/usermod_v2_KITT/usermod_v2_KITT.h
Original file line number Diff line number Diff line change
@@ -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)
// <Effect parameters>(Speed & Fade & Dual checkbox);<Colors>(2 Colours, Fg & Bg);<Palette>(Enabled);<Flags>(1Dim);<Defaults>
const char KITTUsermod::_FX_MODE_KITT[] PROGMEM = "KITT@!,Tail,Delay,,,Dual;!,!;!;1;sx=210";
1 change: 1 addition & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions wled00/usermods_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
/*
Expand Down Expand Up @@ -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
}