FastLED 3.9.15
Loading...
Searching...
No Matches
pride2015.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
12
13// Pride2015
14// Animated, ever-changing rainbows.
15// by Mark Kriegsman
16
18
19class Pride2015 : public Fx1d {
20 public:
21 Pride2015(uint16_t num_leds) : Fx1d(num_leds) {}
22
23 void draw(Fx::DrawContext context) override;
24 fl::Str fxName() const override { return "Pride2015"; }
25
26 private:
27 uint16_t mPseudotime = 0;
28 uint16_t mLastMillis = 0;
29 uint16_t mHue16 = 0;
30};
31
32// This function draws rainbows with an ever-changing,
33// widely-varying set of parameters.
35 if (ctx.leds == nullptr || mNumLeds == 0) {
36 return;
37 }
38
39 uint8_t sat8 = beatsin88(87, 220, 250);
40 uint8_t brightdepth = beatsin88(341, 96, 224);
41 uint16_t brightnessthetainc16 = beatsin88(203, (25 * 256), (40 * 256));
42 uint8_t msmultiplier = beatsin88(147, 23, 60);
43
44 uint16_t hue16 = mHue16;
45 uint16_t hueinc16 = beatsin88(113, 1, 3000);
46
47 uint16_t ms = millis();
48 uint16_t deltams = ms - mLastMillis;
49 mLastMillis = ms;
50 mPseudotime += deltams * msmultiplier;
51 mHue16 += deltams * beatsin88(400, 5, 9);
52 uint16_t brightnesstheta16 = mPseudotime;
53
54 // set master brightness control
55 for (uint16_t i = 0; i < mNumLeds; i++) {
56 hue16 += hueinc16;
57 uint8_t hue8 = hue16 / 256;
58
59 brightnesstheta16 += brightnessthetainc16;
60 uint16_t b16 = sin16(brightnesstheta16) + 32768;
61
62 uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
63 uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
64 bri8 += (255 - brightdepth);
65
66 CRGB newcolor = CHSV(hue8, sat8, bri8);
67
68 uint16_t pixelnumber = (mNumLeds - 1) - i;
69
70 nblend(ctx.leds[pixelnumber], newcolor, 64);
71 }
72}
73
74} // namespace fl
central include file for FastLED, defines the CFastLED class/object
Fx1d(uint16_t numLeds)
Definition fx1d.h:14
uint16_t mNumLeds
Definition fx.h:53
_DrawContext DrawContext
Definition fx.h:21
Pride2015(uint16_t num_leds)
Definition pride2015.h:21
void draw(Fx::DrawContext context) override
Definition pride2015.h:34
uint16_t mPseudotime
Definition pride2015.h:27
uint16_t mHue16
Definition pride2015.h:29
uint16_t mLastMillis
Definition pride2015.h:28
fl::Str fxName() const override
Definition pride2015.h:24
Definition str.h:388
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:921
#define sin16
Platform-independent alias of the fast sin implementation.
Definition trig8.h:103
Implements the FastLED namespace macros.
CRGB & nblend(CRGB &existing, const CRGB &overlay, fract8 amountOfOverlay)
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