FastLED 3.10.8
Loading...
Searching...
No Matches
cylon.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/noexcept.h"
4
5#include "fl/fx/fx1d.h"
6
7namespace fl {
8
10
13class Cylon : public Fx1d {
14 public:
16 Cylon(u16 num_leds, u8 fade_amount = 250, u8 delay_ms = 10) FL_NO_EXCEPT
18
19 void draw(DrawContext context) FL_NO_EXCEPT override {
20 if (context.leds.empty() || mNumLeds == 0) {
21 return;
22 }
23
24 fl::span<CRGB> leds = context.leds;
25
26 // Set the current LED to the current hue
27 leds[position] = CHSV(hue++, 255, 255);
28
29 // Fade all LEDs
30 for (u16 i = 0; i < mNumLeds; i++) {
31 leds[i].nscale8(fade_amount);
32 }
33
34 // Move the position
35 if (reverse) {
36 position--;
37 if (position < 0) {
38 position = 1;
39 reverse = false;
40 }
41 } else {
42 position++;
43 if (position >= i16(mNumLeds)) {
44 position = mNumLeds - 2;
45 reverse = true;
46 }
47 }
48 }
49
50 fl::string fxName() const FL_NO_EXCEPT override { return "Cylon"; }
51
52 private:
53 u8 hue = 0;
54
56
57 bool reverse = false;
58 i16 position = 0;
59};
60
61} // namespace fl
CRGB leds[1]
u8 fade_amount
Definition cylon.h:55
void draw(DrawContext context) FL_NO_EXCEPT override
Definition cylon.h:19
Cylon(u16 num_leds, u8 fade_amount=250, u8 delay_ms=10) FL_NO_EXCEPT
Definition cylon.h:16
bool reverse
Definition cylon.h:57
i16 position
Definition cylon.h:58
u8 hue
Definition cylon.h:53
u8 delay_ms
Definition cylon.h:15
fl::string fxName() const FL_NO_EXCEPT override
Definition cylon.h:50
An animation that moves a single LED back and forth (Larson Scanner effect)
Definition cylon.h:13
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
u16 mNumLeds
Definition fx.h:53
fl::hsv8 CHSV
Definition chsv.h:11
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577