FastLED 3.9.3
Loading...
Searching...
No Matches
cylon.hpp
1#pragma once
2
3#include "FastLED.h"
4#include "fx/fx1d.h"
5#include "namespace.h"
6
7FASTLED_NAMESPACE_BEGIN
8
9FASTLED_SMART_REF(Cylon);
10
13class Cylon : public FxStrip {
14 public:
15 uint8_t delay_ms;
16 Cylon(uint16_t num_leds, uint8_t fade_amount = 250, uint8_t delay_ms = 10)
17 : FxStrip(num_leds), delay_ms(delay_ms), fade_amount(fade_amount) {}
18
19
20
21 void lazyInit() override {
22 // No initialization needed for Cylon
23 }
24
25 void draw(DrawContext context) override {
26 if (context.leds == nullptr || mNumLeds == 0) {
27 return;
28 }
29
30 CRGB *leds = context.leds;
31
32 // Set the current LED to the current hue
33 leds[position] = CHSV(hue++, 255, 255);
34
35 // Fade all LEDs
36 for (uint16_t i = 0; i < mNumLeds; i++) {
37 leds[i].nscale8(fade_amount);
38 }
39
40 // Move the position
41 if (reverse) {
42 position--;
43 if (position < 0) {
44 position = 1;
45 reverse = false;
46 }
47 } else {
48 position++;
49 if (position >= int16_t(mNumLeds)) {
50 position = mNumLeds - 2;
51 reverse = true;
52 }
53 }
54 }
55
56 const char *fxName(int) const override { return "Cylon"; }
57
58 private:
59 uint8_t hue = 0;
60
61 uint8_t fade_amount;
62
63 bool reverse = false;
64 int16_t position = 0;
65};
66
67FASTLED_NAMESPACE_END
central include file for FastLED, defines the CFastLED class/object
An animation that moves a single LED back and forth (Larson Scanner effect)
Definition cylon.hpp:13
void draw(DrawContext context) override
Definition cylon.hpp:25
Definition fx1d.h:12
FASTLED_FORCE_INLINE CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition crgb.hpp:108
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:11
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39