FastLED 3.9.15
Loading...
Searching...
No Matches
cylon.h
Go to the documentation of this file.
1#pragma once
2
3#include "FastLED.h"
4#include "fx/fx1d.h"
5#include "fl/namespace.h"
6
7namespace fl {
8
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)
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
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
central include file for FastLED, defines the CFastLED class/object
uint8_t delay_ms
Definition cylon.h:15
uint8_t fade_amount
Definition cylon.h:56
Cylon(uint16_t num_leds, uint8_t fade_amount=250, uint8_t delay_ms=10)
Definition cylon.h:16
void draw(DrawContext context) override
Definition cylon.h:20
bool reverse
Definition cylon.h:58
uint8_t hue
Definition cylon.h:54
int16_t position
Definition cylon.h:59
fl::Str fxName() const override
Definition cylon.h:51
An animation that moves a single LED back and forth (Larson Scanner effect)
Definition cylon.h:13
Fx1d(uint16_t numLeds)
Definition fx1d.h:14
uint16_t mNumLeds
Definition fx.h:50
_DrawContext DrawContext
Definition fx.h:21
Definition str.h:368
#define FASTLED_SMART_PTR(type)
Definition ptr.h:17
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