FastLED 3.9.7
Loading...
Searching...
No Matches
cylon.hpp
1#pragma once
2
3#include "FastLED.h"
4#include "fx/fx1d.h"
5#include "fl/namespace.h"
6
7namespace fl {
8
9FASTLED_SMART_PTR(Cylon);
10
13class Cylon : public Fx1d {
14 public:
15 uint8_t delay_ms;
16 Cylon(uint16_t num_leds, uint8_t fade_amount = 250, uint8_t delay_ms = 10)
17 : Fx1d(num_leds), delay_ms(delay_ms), fade_amount(fade_amount) {}
18
19
20 void draw(DrawContext context) override {
21 if (context.leds == nullptr || mNumLeds == 0) {
22 return;
23 }
24
25 CRGB *leds = context.leds;
26
27 // Set the current LED to the current hue
28 leds[position] = CHSV(hue++, 255, 255);
29
30 // Fade all LEDs
31 for (uint16_t i = 0; i < mNumLeds; i++) {
32 leds[i].nscale8(fade_amount);
33 }
34
35 // Move the position
36 if (reverse) {
37 position--;
38 if (position < 0) {
39 position = 1;
40 reverse = false;
41 }
42 } else {
43 position++;
44 if (position >= int16_t(mNumLeds)) {
45 position = mNumLeds - 2;
46 reverse = true;
47 }
48 }
49 }
50
51 fl::Str fxName() const override { return "Cylon"; }
52
53 private:
54 uint8_t hue = 0;
55
56 uint8_t fade_amount;
57
58 bool reverse = false;
59 int16_t position = 0;
60};
61
62} // namespace fl
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:20
Definition str.h:336
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
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:111