-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathARGB_Effects.c
More file actions
938 lines (859 loc) · 32.7 KB
/
Copy pathARGB_Effects.c
File metadata and controls
938 lines (859 loc) · 32.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
/**
*******************************************
* @file ARGB_Effects.c
* @author LED Effects Library
* @version 1.0
* @date 14-Oct-2025
* @brief Implementation of 56 LED effects
*******************************************
*/
#include "ARGB_Effects.h"
#include "string.h"
// Effect functions
static void fx_static(ARGB_FX_HandleTypeDef *hfx);
static void fx_blink(ARGB_FX_HandleTypeDef *hfx);
static void fx_breath(ARGB_FX_HandleTypeDef *hfx);
static void fx_color_wipe(ARGB_FX_HandleTypeDef *hfx);
static void fx_color_wipe_inv(ARGB_FX_HandleTypeDef *hfx);
static void fx_color_wipe_rev(ARGB_FX_HandleTypeDef *hfx);
static void fx_color_wipe_rev_inv(ARGB_FX_HandleTypeDef *hfx);
static void fx_color_wipe_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_random_color(ARGB_FX_HandleTypeDef *hfx);
static void fx_single_dynamic(ARGB_FX_HandleTypeDef *hfx);
static void fx_multi_dynamic(ARGB_FX_HandleTypeDef *hfx);
static void fx_rainbow(ARGB_FX_HandleTypeDef *hfx);
static void fx_rainbow_cycle(ARGB_FX_HandleTypeDef *hfx);
static void fx_scan(ARGB_FX_HandleTypeDef *hfx);
static void fx_dual_scan(ARGB_FX_HandleTypeDef *hfx);
static void fx_fade(ARGB_FX_HandleTypeDef *hfx);
static void fx_theater_chase(ARGB_FX_HandleTypeDef *hfx);
static void fx_theater_chase_rainbow(ARGB_FX_HandleTypeDef *hfx);
static void fx_running_lights(ARGB_FX_HandleTypeDef *hfx);
static void fx_twinkle(ARGB_FX_HandleTypeDef *hfx);
static void fx_twinkle_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_twinkle_fade(ARGB_FX_HandleTypeDef *hfx);
static void fx_twinkle_fade_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_sparkle(ARGB_FX_HandleTypeDef *hfx);
static void fx_flash_sparkle(ARGB_FX_HandleTypeDef *hfx);
static void fx_hyper_sparkle(ARGB_FX_HandleTypeDef *hfx);
static void fx_strobe(ARGB_FX_HandleTypeDef *hfx);
static void fx_strobe_rainbow(ARGB_FX_HandleTypeDef *hfx);
static void fx_multi_strobe(ARGB_FX_HandleTypeDef *hfx);
static void fx_blink_rainbow(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_white(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_color(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_rainbow(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_flash(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_flash_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_rainbow_white(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_blackout(ARGB_FX_HandleTypeDef *hfx);
static void fx_chase_blackout_rainbow(ARGB_FX_HandleTypeDef *hfx);
static void fx_color_sweep_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_running_color(ARGB_FX_HandleTypeDef *hfx);
static void fx_running_red_blue(ARGB_FX_HandleTypeDef *hfx);
static void fx_running_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_larson_scanner(ARGB_FX_HandleTypeDef *hfx);
static void fx_comet(ARGB_FX_HandleTypeDef *hfx);
static void fx_fireworks(ARGB_FX_HandleTypeDef *hfx);
static void fx_fireworks_random(ARGB_FX_HandleTypeDef *hfx);
static void fx_merry_christmas(ARGB_FX_HandleTypeDef *hfx);
static void fx_fire_flicker(ARGB_FX_HandleTypeDef *hfx);
static void fx_fire_flicker_soft(ARGB_FX_HandleTypeDef *hfx);
static void fx_fire_flicker_intense(ARGB_FX_HandleTypeDef *hfx);
static void fx_circus_combustus(ARGB_FX_HandleTypeDef *hfx);
static void fx_halloween(ARGB_FX_HandleTypeDef *hfx);
static void fx_bicolor_chase(ARGB_FX_HandleTypeDef *hfx);
static void fx_tricolor_chase(ARGB_FX_HandleTypeDef *hfx);
static void fx_twinklefox(ARGB_FX_HandleTypeDef *hfx);
// Effect function pointer array
typedef void (*fx_function)(ARGB_FX_HandleTypeDef *);
static const fx_function fx_functions[] = {
fx_static, fx_blink, fx_breath, fx_color_wipe, fx_color_wipe_inv,
fx_color_wipe_rev, fx_color_wipe_rev_inv, fx_color_wipe_random,
fx_random_color, fx_single_dynamic, fx_multi_dynamic, fx_rainbow,
fx_rainbow_cycle, fx_scan, fx_dual_scan, fx_fade, fx_theater_chase,
fx_theater_chase_rainbow, fx_running_lights, fx_twinkle, fx_twinkle_random,
fx_twinkle_fade, fx_twinkle_fade_random, fx_sparkle, fx_flash_sparkle,
fx_hyper_sparkle, fx_strobe, fx_strobe_rainbow, fx_multi_strobe,
fx_blink_rainbow, fx_chase_white, fx_chase_color, fx_chase_random,
fx_chase_rainbow, fx_chase_flash, fx_chase_flash_random,
fx_chase_rainbow_white, fx_chase_blackout, fx_chase_blackout_rainbow,
fx_color_sweep_random, fx_running_color, fx_running_red_blue,
fx_running_random, fx_larson_scanner, fx_comet, fx_fireworks,
fx_fireworks_random, fx_merry_christmas, fx_fire_flicker,
fx_fire_flicker_soft, fx_fire_flicker_intense, fx_circus_combustus,
fx_halloween, fx_bicolor_chase, fx_tricolor_chase, fx_twinklefox
};
/**
* @brief Initialize effect handle
*/
void ARGB_FX_Init(ARGB_FX_HandleTypeDef *hfx, ARGB_HandleTypeDef *hargb) {
hfx->hargb = hargb;
hfx->mode = FX_MODE_STATIC;
hfx->color = COLOR_RED;
hfx->color2 = COLOR_GREEN;
hfx->color3 = COLOR_BLUE;
hfx->speed = 100;
hfx->counter = 0;
hfx->aux_param = 0;
hfx->aux_param2 = 0;
hfx->reverse = 0;
}
void ARGB_FX_SetMode(ARGB_FX_HandleTypeDef *hfx, ARGB_FX_MODE mode) {
if (mode >= FX_MODE_COUNT) return;
hfx->mode = mode;
hfx->counter = 0;
hfx->aux_param = 0;
hfx->aux_param2 = 0;
}
void ARGB_FX_SetColor(ARGB_FX_HandleTypeDef *hfx, ARGB_RGB color) {
hfx->color = color;
}
void ARGB_FX_SetColors(ARGB_FX_HandleTypeDef *hfx, ARGB_RGB c1, ARGB_RGB c2, ARGB_RGB c3) {
hfx->color = c1;
hfx->color2 = c2;
hfx->color3 = c3;
}
void ARGB_FX_SetSpeed(ARGB_FX_HandleTypeDef *hfx, uint16_t speed) {
hfx->speed = speed > 0 ? speed : 1;
}
void ARGB_FX_SetReverse(ARGB_FX_HandleTypeDef *hfx, uint8_t reverse) {
hfx->reverse = reverse;
}
/**
* @brief Service function - call periodically to update effects
*/
void ARGB_FX_Service(ARGB_FX_HandleTypeDef *hfx) {
if (ARGB_Ready(hfx->hargb) != ARGB_READY) return;
if (hfx->mode < FX_MODE_COUNT) {
fx_functions[hfx->mode](hfx);
ARGB_Show(hfx->hargb);
}
}
// Random number generators
uint8_t random8(void) {
return (uint8_t)rand();
}
uint16_t random16(void) {
return (uint16_t)rand();
}
uint32_t random32(void) {
return (uint32_t)rand();
}
uint8_t random8_range(uint8_t min, uint8_t max) {
if (min >= max) return min;
return min + (random8() % (max - min));
}
/**
* @brief Color wheel - generates rainbow colors
*/
ARGB_RGB color_wheel(uint8_t pos) {
ARGB_RGB c;
if (pos < 85) {
c.r = pos * 3;
c.g = 255 - pos * 3;
c.b = 0;
} else if (pos < 170) {
pos -= 85;
c.r = 255 - pos * 3;
c.g = 0;
c.b = pos * 3;
} else {
pos -= 170;
c.r = 0;
c.g = pos * 3;
c.b = 255 - pos * 3;
}
return c;
}
/**
* @brief Blend two colors
*/
ARGB_RGB color_blend(ARGB_RGB c1, ARGB_RGB c2, uint8_t blend) {
ARGB_RGB result;
result.r = ((uint16_t)c1.r * (255 - blend) + (uint16_t)c2.r * blend) / 255;
result.g = ((uint16_t)c1.g * (255 - blend) + (uint16_t)c2.g * blend) / 255;
result.b = ((uint16_t)c1.b * (255 - blend) + (uint16_t)c2.b * blend) / 255;
return result;
}
// ========== Effect Implementations ==========
// 1. Static
static void fx_static(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter == 0) {
ARGB_FillRGB(hfx->hargb, hfx->color);
hfx->counter = 1;
}
}
// 2. Blink
static void fx_blink(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % (hfx->speed * 2) < hfx->speed) {
ARGB_FillRGB(hfx->hargb, hfx->color);
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 3. Breath
static void fx_breath(ARGB_FX_HandleTypeDef *hfx) {
float breath = (exp(sin((float)hfx->counter / hfx->speed * 3.14159)) - 0.36787944) * 108.0;
uint8_t br = (uint8_t)breath;
ARGB_SetBrightness(hfx->hargb, br);
ARGB_FillRGB(hfx->hargb, hfx->color);
hfx->counter++;
}
// 4. Color Wipe
static void fx_color_wipe(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % (hfx->hargb->num_pixels * 2);
if (pos < hfx->hargb->num_pixels) {
ARGB_SetRGB(hfx->hargb, pos, hfx->color);
} else {
ARGB_SetRGB(hfx->hargb, pos - hfx->hargb->num_pixels, COLOR_BLACK);
}
hfx->counter++;
}
// 5. Color Wipe Inverse
static void fx_color_wipe_inv(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % (hfx->hargb->num_pixels * 2);
if (pos < hfx->hargb->num_pixels) {
ARGB_SetRGB(hfx->hargb, pos, COLOR_BLACK);
} else {
ARGB_SetRGB(hfx->hargb, pos - hfx->hargb->num_pixels, hfx->color);
}
hfx->counter++;
}
// 6. Color Wipe Reverse
static void fx_color_wipe_rev(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % (hfx->hargb->num_pixels * 2);
if (pos < hfx->hargb->num_pixels) {
ARGB_SetRGB(hfx->hargb, pos, hfx->color);
} else {
ARGB_SetRGB(hfx->hargb, hfx->hargb->num_pixels * 2 - pos - 1, COLOR_BLACK);
}
hfx->counter++;
}
// 7. Color Wipe Reverse Inverse
static void fx_color_wipe_rev_inv(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % (hfx->hargb->num_pixels * 2);
if (pos < hfx->hargb->num_pixels) {
ARGB_SetRGB(hfx->hargb, pos, COLOR_BLACK);
} else {
ARGB_SetRGB(hfx->hargb, hfx->hargb->num_pixels * 2 - pos - 1, hfx->color);
}
hfx->counter++;
}
// 8. Color Wipe Random
static void fx_color_wipe_random(ARGB_FX_HandleTypeDef *hfx) {
if ((hfx->counter / hfx->speed) % hfx->hargb->num_pixels == 0) {
hfx->aux_param = random8();
}
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
ARGB_SetRGB(hfx->hargb, pos, color_wheel(hfx->aux_param));
hfx->counter++;
}
// 9. Random Color
static void fx_random_color(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % (hfx->speed * 10) == 0) {
ARGB_FillRGB(hfx->hargb, color_wheel(random8()));
}
hfx->counter++;
}
// 10. Single Dynamic
static void fx_single_dynamic(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_SetRGB(hfx->hargb, i, color_wheel(random8()));
}
}
if (hfx->counter % hfx->speed == 0) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, color_wheel(random8()));
}
hfx->counter++;
}
// 11. Multi Dynamic
static void fx_multi_dynamic(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_SetRGB(hfx->hargb, i, color_wheel(random8()));
}
}
hfx->counter++;
}
// 12. Rainbow
static void fx_rainbow(ARGB_FX_HandleTypeDef *hfx) {
uint8_t pos = (hfx->counter / hfx->speed) & 0xFF;
ARGB_FillRGB(hfx->hargb, color_wheel(pos));
hfx->counter++;
}
// 13. Rainbow Cycle
static void fx_rainbow_cycle(ARGB_FX_HandleTypeDef *hfx) {
uint8_t offset = (hfx->counter / hfx->speed) & 0xFF;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_SetRGB(hfx->hargb, i, color_wheel(((i * 256 / hfx->hargb->num_pixels) + offset) & 0xFF));
}
hfx->counter++;
}
// 14. Scan
static void fx_scan(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % (hfx->hargb->num_pixels * 2 - 2);
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
if (pos < hfx->hargb->num_pixels) {
ARGB_SetRGB(hfx->hargb, pos, hfx->color);
} else {
ARGB_SetRGB(hfx->hargb, hfx->hargb->num_pixels * 2 - pos - 2, hfx->color);
}
hfx->counter++;
}
// 15. Dual Scan
static void fx_dual_scan(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % (hfx->hargb->num_pixels - 1);
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
ARGB_SetRGB(hfx->hargb, pos, hfx->color);
ARGB_SetRGB(hfx->hargb, hfx->hargb->num_pixels - pos - 1, hfx->color);
hfx->counter++;
}
// 16. Fade
static void fx_fade(ARGB_FX_HandleTypeDef *hfx) {
uint8_t fade = ((hfx->counter / hfx->speed) % 510);
if (fade > 255) fade = 510 - fade;
ARGB_RGB c = {
(uint8_t)(hfx->color.r * fade / 255),
(uint8_t)(hfx->color.g * fade / 255),
(uint8_t)(hfx->color.b * fade / 255)
};
ARGB_FillRGB(hfx->hargb, c);
hfx->counter++;
}
// 17. Theater Chase
static void fx_theater_chase(ARGB_FX_HandleTypeDef *hfx) {
uint8_t pos = (hfx->counter / hfx->speed) % 3;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if ((i % 3) == pos) {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_BLACK);
}
}
hfx->counter++;
}
// 18. Theater Chase Rainbow
static void fx_theater_chase_rainbow(ARGB_FX_HandleTypeDef *hfx) {
uint8_t pos = (hfx->counter / hfx->speed) % 3;
uint8_t wheel_pos = (hfx->counter / (hfx->speed * 3)) & 0xFF;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if ((i % 3) == pos) {
ARGB_SetRGB(hfx->hargb, i, color_wheel(wheel_pos));
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_BLACK);
}
}
hfx->counter++;
}
// 19. Running Lights
static void fx_running_lights(ARGB_FX_HandleTypeDef *hfx) {
float pos = (float)hfx->counter / hfx->speed;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t level = (uint8_t)(sin(i + pos) * 127 + 128);
ARGB_RGB c = {
(uint8_t)(hfx->color.r * level / 255),
(uint8_t)(hfx->color.g * level / 255),
(uint8_t)(hfx->color.b * level / 255)
};
ARGB_SetRGB(hfx->hargb, i, c);
}
hfx->counter++;
}
// 20. Twinkle
static void fx_twinkle(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
for (int i = 0; i < hfx->hargb->num_pixels / 4; i++) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, hfx->color);
}
}
hfx->counter++;
}
// 21. Twinkle Random
static void fx_twinkle_random(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
for (int i = 0; i < hfx->hargb->num_pixels / 4; i++) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, color_wheel(random8()));
}
}
hfx->counter++;
}
// 22. Twinkle Fade
static void fx_twinkle_fade(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_RGB c = {
hfx->hargb->rgb_buf[i * 3] * 9 / 10,
hfx->hargb->rgb_buf[i * 3 + 1] * 9 / 10,
hfx->hargb->rgb_buf[i * 3 + 2] * 9 / 10
};
ARGB_SetRGB(hfx->hargb, i, c);
}
if (random8() < 80) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, hfx->color);
}
}
hfx->counter++;
}
// 23. Twinkle Fade Random
static void fx_twinkle_fade_random(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_RGB c = {
hfx->hargb->rgb_buf[i * 3] * 9 / 10,
hfx->hargb->rgb_buf[i * 3 + 1] * 9 / 10,
hfx->hargb->rgb_buf[i * 3 + 2] * 9 / 10
};
ARGB_SetRGB(hfx->hargb, i, c);
}
if (random8() < 80) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, color_wheel(random8()));
}
}
hfx->counter++;
}
// 24. Sparkle
static void fx_sparkle(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, COLOR_WHITE);
}
hfx->counter++;
}
// 25. Flash Sparkle
static void fx_flash_sparkle(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
ARGB_FillRGB(hfx->hargb, hfx->color);
if (random8() < 50) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, COLOR_WHITE);
}
}
hfx->counter++;
}
// 26. Hyper Sparkle
static void fx_hyper_sparkle(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
ARGB_FillRGB(hfx->hargb, hfx->color);
for (int i = 0; i < hfx->hargb->num_pixels / 8; i++) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, COLOR_WHITE);
}
}
hfx->counter++;
}
// 27. Strobe
static void fx_strobe(ARGB_FX_HandleTypeDef *hfx) {
uint16_t cycle = hfx->counter % (hfx->speed * 10);
if (cycle < hfx->speed) {
ARGB_FillRGB(hfx->hargb, hfx->color);
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 28. Strobe Rainbow
static void fx_strobe_rainbow(ARGB_FX_HandleTypeDef *hfx) {
uint16_t cycle = hfx->counter % (hfx->speed * 10);
if (cycle < hfx->speed) {
ARGB_FillRGB(hfx->hargb, color_wheel((hfx->counter / (hfx->speed * 10)) & 0xFF));
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 29. Multi Strobe
static void fx_multi_strobe(ARGB_FX_HandleTypeDef *hfx) {
uint8_t strobe_count = 4;
uint16_t cycle_len = hfx->speed * (strobe_count * 2 + 10);
uint16_t pos = hfx->counter % cycle_len;
if (pos < strobe_count * hfx->speed * 2) {
if ((pos / hfx->speed) % 2 == 0) {
ARGB_FillRGB(hfx->hargb, hfx->color);
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 30. Blink Rainbow
static void fx_blink_rainbow(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % (hfx->speed * 2) < hfx->speed) {
ARGB_FillRGB(hfx->hargb, color_wheel((hfx->counter / (hfx->speed * 2)) & 0xFF));
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 31. Chase White
static void fx_chase_white(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
} else {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
}
}
hfx->counter++;
}
// 32. Chase Color
static void fx_chase_color(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
}
}
hfx->counter++;
}
// 33. Chase Random
static void fx_chase_random(ARGB_FX_HandleTypeDef *hfx) {
if ((hfx->counter / hfx->speed) % hfx->hargb->num_pixels == 0) {
hfx->aux_param = random8();
}
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
} else {
ARGB_SetRGB(hfx->hargb, i, color_wheel(hfx->aux_param));
}
}
hfx->counter++;
}
// 34. Chase Rainbow
static void fx_chase_rainbow(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
uint8_t wheel_offset = (hfx->counter / (hfx->speed * hfx->hargb->num_pixels)) & 0xFF;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
} else {
ARGB_SetRGB(hfx->hargb, i, color_wheel((i * 256 / hfx->hargb->num_pixels + wheel_offset) & 0xFF));
}
}
hfx->counter++;
}
// 35. Chase Flash
static void fx_chase_flash(ARGB_FX_HandleTypeDef *hfx) {
uint16_t cycle = hfx->counter % (hfx->speed * hfx->hargb->num_pixels + hfx->speed * 10);
if (cycle < hfx->speed * hfx->hargb->num_pixels) {
uint16_t pos = cycle / hfx->speed;
ARGB_FillRGB(hfx->hargb, hfx->color);
ARGB_SetRGB(hfx->hargb, pos, COLOR_WHITE);
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 36. Chase Flash Random
static void fx_chase_flash_random(ARGB_FX_HandleTypeDef *hfx) {
uint16_t cycle_len = hfx->speed * hfx->hargb->num_pixels + hfx->speed * 10;
if (hfx->counter % cycle_len == 0) {
hfx->aux_param = random8();
}
uint16_t cycle = hfx->counter % cycle_len;
if (cycle < hfx->speed * hfx->hargb->num_pixels) {
uint16_t pos = cycle / hfx->speed;
ARGB_FillRGB(hfx->hargb, color_wheel(hfx->aux_param));
ARGB_SetRGB(hfx->hargb, pos, COLOR_WHITE);
} else {
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
}
hfx->counter++;
}
// 37. Chase Rainbow White
static void fx_chase_rainbow_white(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, color_wheel((i * 256 / hfx->hargb->num_pixels) & 0xFF));
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
}
}
hfx->counter++;
}
// 38. Chase Blackout
static void fx_chase_blackout(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, COLOR_BLACK);
} else {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
}
}
hfx->counter++;
}
// 39. Chase Blackout Rainbow
static void fx_chase_blackout_rainbow(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
uint8_t wheel_offset = (hfx->counter / (hfx->speed * hfx->hargb->num_pixels)) & 0xFF;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos) {
ARGB_SetRGB(hfx->hargb, i, COLOR_BLACK);
} else {
ARGB_SetRGB(hfx->hargb, i, color_wheel((i * 256 / hfx->hargb->num_pixels + wheel_offset) & 0xFF));
}
}
hfx->counter++;
}
// 40. Color Sweep Random
static void fx_color_sweep_random(ARGB_FX_HandleTypeDef *hfx) {
uint16_t cycle = hfx->counter / hfx->speed;
if (cycle % hfx->hargb->num_pixels == 0) {
hfx->aux_param = random8();
}
uint16_t pos = cycle % hfx->hargb->num_pixels;
if ((cycle / hfx->hargb->num_pixels) % 2 == 0) {
ARGB_SetRGB(hfx->hargb, pos, color_wheel(hfx->aux_param));
} else {
ARGB_SetRGB(hfx->hargb, hfx->hargb->num_pixels - pos - 1, color_wheel(hfx->aux_param));
}
hfx->counter++;
}
// 41. Running Color
static void fx_running_color(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if ((i + pos) % 2 == 0) {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
}
}
hfx->counter++;
}
// 42. Running Red Blue
static void fx_running_red_blue(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if ((i + pos) % 2 == 0) {
ARGB_SetRGB(hfx->hargb, i, COLOR_RED);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_BLUE);
}
}
hfx->counter++;
}
// 43. Running Random
static void fx_running_random(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = hfx->hargb->num_pixels - 1; i > 0; i--) {
uint8_t idx = i * 3;
hfx->hargb->rgb_buf[idx] = hfx->hargb->rgb_buf[idx - 3];
hfx->hargb->rgb_buf[idx + 1] = hfx->hargb->rgb_buf[idx - 2];
hfx->hargb->rgb_buf[idx + 2] = hfx->hargb->rgb_buf[idx - 1];
}
ARGB_SetRGB(hfx->hargb, 0, color_wheel(random8()));
}
hfx->counter++;
}
// 44. Larson Scanner (K.I.T.T.)
static void fx_larson_scanner(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % ((hfx->hargb->num_pixels - 1) * 2);
ARGB_FillRGB(hfx->hargb, COLOR_BLACK);
uint16_t led_pos;
if (pos < hfx->hargb->num_pixels) {
led_pos = pos;
} else {
led_pos = (hfx->hargb->num_pixels - 1) * 2 - pos;
}
ARGB_SetRGB(hfx->hargb, led_pos, hfx->color);
if (led_pos > 0) {
ARGB_RGB c = {hfx->color.r / 4, hfx->color.g / 4, hfx->color.b / 4};
ARGB_SetRGB(hfx->hargb, led_pos - 1, c);
}
if (led_pos < hfx->hargb->num_pixels - 1) {
ARGB_RGB c = {hfx->color.r / 4, hfx->color.g / 4, hfx->color.b / 4};
ARGB_SetRGB(hfx->hargb, led_pos + 1, c);
}
hfx->counter++;
}
// 45. Comet
static void fx_comet(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_RGB c = {
hfx->hargb->rgb_buf[i * 3] * 9 / 10,
hfx->hargb->rgb_buf[i * 3 + 1] * 9 / 10,
hfx->hargb->rgb_buf[i * 3 + 2] * 9 / 10
};
ARGB_SetRGB(hfx->hargb, i, c);
}
ARGB_SetRGB(hfx->hargb, pos, hfx->color);
hfx->counter++;
}
// 46. Fireworks
static void fx_fireworks(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_RGB c = {
hfx->hargb->rgb_buf[i * 3] * 95 / 100,
hfx->hargb->rgb_buf[i * 3 + 1] * 95 / 100,
hfx->hargb->rgb_buf[i * 3 + 2] * 95 / 100
};
ARGB_SetRGB(hfx->hargb, i, c);
}
if (random8() < 20) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, hfx->color);
}
}
hfx->counter++;
}
// 47. Fireworks Random
static void fx_fireworks_random(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
ARGB_RGB c = {
hfx->hargb->rgb_buf[i * 3] * 95 / 100,
hfx->hargb->rgb_buf[i * 3 + 1] * 95 / 100,
hfx->hargb->rgb_buf[i * 3 + 2] * 95 / 100
};
ARGB_SetRGB(hfx->hargb, i, c);
}
if (random8() < 20) {
ARGB_SetRGB(hfx->hargb, random16() % hfx->hargb->num_pixels, color_wheel(random8()));
}
}
hfx->counter++;
}
// 48. Merry Christmas
static void fx_merry_christmas(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if ((i + pos) % 2 == 0) {
ARGB_SetRGB(hfx->hargb, i, COLOR_RED);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_GREEN);
}
}
hfx->counter++;
}
// 49. Fire Flicker
static void fx_fire_flicker(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t flicker = random8_range(150, 255);
ARGB_RGB c = {
(uint8_t)(hfx->color.r * flicker / 255),
(uint8_t)(hfx->color.g * flicker / 255),
(uint8_t)(hfx->color.b * flicker / 255)
};
ARGB_SetRGB(hfx->hargb, i, c);
}
}
hfx->counter++;
}
// 50. Fire Flicker Soft
static void fx_fire_flicker_soft(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % (hfx->speed * 2) == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t flicker = random8_range(180, 255);
ARGB_RGB c = {
(uint8_t)(hfx->color.r * flicker / 255),
(uint8_t)(hfx->color.g * flicker / 255),
(uint8_t)(hfx->color.b * flicker / 255)
};
ARGB_SetRGB(hfx->hargb, i, c);
}
}
hfx->counter++;
}
// 51. Fire Flicker Intense
static void fx_fire_flicker_intense(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t flicker = random8_range(100, 255);
ARGB_RGB fire_color;
fire_color.r = 255;
fire_color.g = random8_range(0, 100);
fire_color.b = 0;
ARGB_RGB c = {
(uint8_t)(fire_color.r * flicker / 255),
(uint8_t)(fire_color.g * flicker / 255),
(uint8_t)(fire_color.b * flicker / 255)
};
ARGB_SetRGB(hfx->hargb, i, c);
}
}
hfx->counter++;
}
// 52. Circus Combustus
static void fx_circus_combustus(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t mod = (i + pos) % 3;
if (mod == 0) {
ARGB_SetRGB(hfx->hargb, i, COLOR_WHITE);
} else if (mod == 1) {
ARGB_SetRGB(hfx->hargb, i, COLOR_RED);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_BLACK);
}
}
hfx->counter++;
}
// 53. Halloween
static void fx_halloween(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if ((i + pos) % 2 == 0) {
ARGB_SetRGB(hfx->hargb, i, COLOR_ORANGE);
} else {
ARGB_SetRGB(hfx->hargb, i, COLOR_PURPLE);
}
}
hfx->counter++;
}
// 54. Bicolor Chase
static void fx_bicolor_chase(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
if (i == pos || i == (pos + 1) % hfx->hargb->num_pixels) {
ARGB_SetRGB(hfx->hargb, i, hfx->color2);
} else {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
}
}
hfx->counter++;
}
// 55. Tricolor Chase
static void fx_tricolor_chase(ARGB_FX_HandleTypeDef *hfx) {
uint16_t pos = (hfx->counter / hfx->speed) % hfx->hargb->num_pixels;
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t mod = (i + pos) % 3;
if (mod == 0) {
ARGB_SetRGB(hfx->hargb, i, hfx->color);
} else if (mod == 1) {
ARGB_SetRGB(hfx->hargb, i, hfx->color2);
} else {
ARGB_SetRGB(hfx->hargb, i, hfx->color3);
}
}
hfx->counter++;
}
// 56. TwinkleFOX
static void fx_twinklefox(ARGB_FX_HandleTypeDef *hfx) {
if (hfx->counter % hfx->speed == 0) {
for (uint16_t i = 0; i < hfx->hargb->num_pixels; i++) {
uint8_t brightness = (uint8_t)(sin((float)((hfx->counter / hfx->speed + i * 13) % 256) * 0.0245) * 127 + 128);
ARGB_RGB c = {
(uint8_t)(hfx->color.r * brightness / 255),
(uint8_t)(hfx->color.g * brightness / 255),
(uint8_t)(hfx->color.b * brightness / 255)
};
ARGB_SetRGB(hfx->hargb, i, c);
}
}
hfx->counter++;
}