FastLED 3.9.15
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages

◆ loop()

void loop ( )

Definition at line 84 of file FxWater.ino.

84 {
85 // swap the src/dest buffers on each frame
86 static uint8_t buffer = 0;
87 uint8_t * const bufA = &water[buffer][0];
88 buffer = (buffer + 1) % 2;
89 uint8_t * const bufB = &water[buffer][0];
90
91 // add a moving stimulus
92 wu_water(bufA, beatsin16(13, 256, HEIGHT * 256), beatsin16(7, 256, WIDTH * 256), beatsin8(160, 64, 255));
93
94 // animate the water
95 process_water(bufA, bufB);
96
97
98 // display the water effect on the LEDs
99 uint8_t * input = bufB + WATERWIDTH - 1;
100 static uint16_t pal_offset = 0;
101 pal_offset += 256;
102 for (uint8_t y = 0; y < HEIGHT; y++) {
103 input += 2;
104 for (uint8_t x = 0; x < WIDTH; x++) {
105 leds[XY(x, y)] = MyColorFromPaletteExtended(RainbowColors_p, pal_offset + (*input++ << 8), 255, LINEARBLEND);
106 }
107 }
108 FastLED.show();
109}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define WIDTH
Definition Blur2d.ino:9
#define HEIGHT
Definition Blur2d.ino:10
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
void process_water(uint8_t *src, uint8_t *dst)
Definition FxWater.ino:111
uint16_t XY(uint8_t x, uint8_t y)
Definition FxWater.ino:80
void wu_water(uint8_t *const buf, uint16_t x, uint16_t y, uint8_t bright)
Definition FxWater.ino:131
CRGB MyColorFromPaletteExtended(const CRGBPalette16 &pal, uint16_t index, uint8_t brightness, TBlendType blendType)
Definition FxWater.ino:30
uint8_t water[2][WATERWIDTH *WATERHEIGHT]
Definition FxWater.ino:19
#define WATERWIDTH
Definition FxWater.ino:17
LIB8STATIC uint16_t beatsin16(accum88 beats_per_minute, 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:957
LIB8STATIC uint8_t beatsin8(accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:975
@ LINEARBLEND
Linear interpolation between palette entries, with wrap-around from end to the beginning again.
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.

References beatsin16(), beatsin8(), FastLED, HEIGHT, leds, LINEARBLEND, MyColorFromPaletteExtended(), process_water(), RainbowColors_p, water, WATERWIDTH, WIDTH, wu_water(), x, XY(), and y.

+ Here is the call graph for this function: