FastLED 3.9.3
Loading...
Searching...
No Matches
pride2015.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "FastLED.h"
4#include "fx/fx1d.h"
5#include "namespace.h"
6
7FASTLED_NAMESPACE_BEGIN
8
9
10
14
15// Pride2015
16// Animated, ever-changing rainbows.
17// by Mark Kriegsman
18
19FASTLED_SMART_REF(Pride2015);
20
21class Pride2015 : public FxStrip {
22 public:
23 Pride2015(uint16_t num_leds) : FxStrip(num_leds) {}
24
25 void lazyInit() override {}
26 void draw(Fx::DrawContext context) override;
27 const char *fxName(int) const override { return "Pride2015"; }
28
29 private:
30 uint16_t mPseudotime = 0;
31 uint16_t mLastMillis = 0;
32 uint16_t mHue16 = 0;
33};
34
35// This function draws rainbows with an ever-changing,
36// widely-varying set of parameters.
38 if (ctx.leds == nullptr || mNumLeds == 0) {
39 return;
40 }
41
42 uint8_t sat8 = beatsin88(87, 220, 250);
43 uint8_t brightdepth = beatsin88(341, 96, 224);
44 uint16_t brightnessthetainc16 = beatsin88(203, (25 * 256), (40 * 256));
45 uint8_t msmultiplier = beatsin88(147, 23, 60);
46
47 uint16_t hue16 = mHue16;
48 uint16_t hueinc16 = beatsin88(113, 1, 3000);
49
50 uint16_t ms = millis();
51 uint16_t deltams = ms - mLastMillis;
52 mLastMillis = ms;
53 mPseudotime += deltams * msmultiplier;
54 mHue16 += deltams * beatsin88(400, 5, 9);
55 uint16_t brightnesstheta16 = mPseudotime;
56
57 // set master brightness control
58 for (uint16_t i = 0; i < mNumLeds; i++) {
59 hue16 += hueinc16;
60 uint8_t hue8 = hue16 / 256;
61
62 brightnesstheta16 += brightnessthetainc16;
63 uint16_t b16 = sin16(brightnesstheta16) + 32768;
64
65 uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
66 uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
67 bri8 += (255 - brightdepth);
68
69 CRGB newcolor = CHSV(hue8, sat8, bri8);
70
71 uint16_t pixelnumber = (mNumLeds - 1) - i;
72
73 nblend(ctx.leds[pixelnumber], newcolor, 64);
74 }
75}
76
77FASTLED_NAMESPACE_END
central include file for FastLED, defines the CFastLED class/object
Definition fx1d.h:12
void draw(Fx::DrawContext context) override
Definition pride2015.hpp:37
LIB8STATIC uint16_t beatsin88(accum88 beats_per_minute_88, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:944
CRGB & nblend(CRGB &existing, const CRGB &overlay, fract8 amountOfOverlay)
Destructively modifies one color, blending in a given fraction of an overlay color.
#define sin16
Platform-independent alias of the fast sin implementation.
Definition trig8.h:91
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