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

Effect: modified KITT (Scanner) #3763

Merged
merged 2 commits into from
Apr 10, 2024
Merged
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
71 changes: 38 additions & 33 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,57 +1125,62 @@ uint16_t mode_running_random(void) {
static const char _data_FX_MODE_RUNNING_RANDOM[] PROGMEM = "Stream@!,Zone size;;!";


uint16_t larson_scanner(bool dual) {
/*
* K.I.T.T.
*/
uint16_t mode_larson_scanner(void){
if (SEGLEN == 1) return mode_static();
uint16_t counter = strip.now * ((SEGMENT.speed >> 2) +8);
uint16_t index = (counter * SEGLEN) >> 16;

SEGMENT.fade_out(SEGMENT.intensity);
const unsigned speed = FRAMETIME * map(SEGMENT.speed, 0, 255, 96, 2); // map into useful range
const unsigned pixels = SEGLEN / speed; // how many pixels to advance per frame

if (SEGENV.step > index && SEGENV.step - index > SEGLEN/2) {
SEGENV.aux0 = !SEGENV.aux0;
}
SEGMENT.fade_out(255-SEGMENT.intensity);

if (SEGENV.step > strip.now) return FRAMETIME; // we have a pause

for (int i = SEGENV.step; i < index; i++) {
uint16_t j = (SEGENV.aux0)?i:SEGLEN-1-i;
SEGMENT.setPixelColor( j, SEGMENT.color_from_palette(j, true, PALETTE_SOLID_WRAP, 0));
unsigned index = SEGENV.aux1 + pixels;
// are we slow enough to use frames per pixel?
if (pixels == 0) {
const unsigned frames = speed / SEGLEN; // how many frames per 1 pixel
if (SEGENV.step++ < frames) return FRAMETIME;
SEGENV.step = 0;
index++;
}
if (dual) {
uint32_t c;
if (SEGCOLOR(2) != 0) {
c = SEGCOLOR(2);
} else {
c = SEGMENT.color_from_palette(index, true, PALETTE_SOLID_WRAP, 0);
}

for (int i = SEGENV.step; i < index; i++) {
uint16_t j = (SEGENV.aux0)?SEGLEN-1-i:i;
if (index > SEGLEN) {

SEGENV.aux0 = !SEGENV.aux0; // change direction
SEGENV.aux1 = 0; // reset position
// set delay
if (SEGENV.aux0 || SEGMENT.check2) SEGENV.step = strip.now + SEGMENT.custom1 * 25; // multiply by 25ms
else SEGENV.step = 0;

} else {

// paint as many pixels as needed
for (unsigned i = SEGENV.aux1; i < index; i++) {
unsigned j = (SEGENV.aux0) ? i : SEGLEN - 1 - i;
uint32_t c = SEGMENT.color_from_palette(j, true, PALETTE_SOLID_WRAP, 0);
SEGMENT.setPixelColor(j, c);
if (SEGMENT.check1) {
SEGMENT.setPixelColor(SEGLEN - 1 - j, SEGCOLOR(2) ? SEGCOLOR(2) : c);
}
}
SEGENV.aux1 = index;
}

SEGENV.step = index;
return FRAMETIME;
}


/*
* K.I.T.T.
*/
uint16_t mode_larson_scanner(void){
return larson_scanner(false);
}
static const char _data_FX_MODE_LARSON_SCANNER[] PROGMEM = "Scanner@!,Fade rate;!,!;!;;m12=0";

static const char _data_FX_MODE_LARSON_SCANNER[] PROGMEM = "Scanner@!,Trail,Delay,,,Dual,Bi-delay;!,!,!;!;;m12=0,c1=0";

/*
* Creates two Larson scanners moving in opposite directions
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/DualLarson.h
*/
uint16_t mode_dual_larson_scanner(void){
return larson_scanner(true);
SEGMENT.check1 = true;
return mode_larson_scanner();
}
static const char _data_FX_MODE_DUAL_LARSON_SCANNER[] PROGMEM = "Scanner Dual@!,Fade rate;!,!,!;!;;m12=0";
static const char _data_FX_MODE_DUAL_LARSON_SCANNER[] PROGMEM = "Scanner Dual@!,Trail,Delay,,,Dual,Bi-delay;!,!,!;!;;m12=0,c1=0";


/*
Expand Down
2 changes: 1 addition & 1 deletion wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
#define FX_MODE_LIGHTNING 57
#define FX_MODE_ICU 58
#define FX_MODE_MULTI_COMET 59
#define FX_MODE_DUAL_LARSON_SCANNER 60
#define FX_MODE_DUAL_LARSON_SCANNER 60 // candidate for removal (use Scanner with with check 1)
#define FX_MODE_RANDOM_CHASE 61
#define FX_MODE_OSCILLATE 62
#define FX_MODE_PRIDE_2015 63
Expand Down