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 "fl/namespace.h"
5#include "fx/fx1d.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 void draw(DrawContext context) override {
20 if (context.leds == nullptr || mNumLeds == 0) {
21 return;
22 }
23
24 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 (uint16_t 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 >= int16_t(mNumLeds)) {
44 position = mNumLeds - 2;
45 reverse = true;
46 }
47 }
48 }
49
50 fl::Str fxName() const override { return "Cylon"; }
51
52 private:
53 uint8_t hue = 0;
54
55 uint8_t fade_amount;
56
57 bool reverse = false;
58 int16_t position = 0;
59};
60
61} // 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:55
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:19
bool reverse
Definition cylon.h:57
uint8_t hue
Definition cylon.h:53
int16_t position
Definition cylon.h:58
fl::Str fxName() const override
Definition cylon.h:50
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:53
_DrawContext DrawContext
Definition fx.h:21
Definition str.h:388
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
#define FASTLED_SMART_PTR(type)
Definition ptr.h:31
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:55