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