Skip to content

Commit 29cbda5

Browse files
committed
Add example
1 parent 9202142 commit 29cbda5

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
#include <FastLEDHub.h>
4+
5+
class RbWave : public Animation
6+
{
7+
public:
8+
using Animation::Animation;
9+
10+
void reset()
11+
{
12+
step = 0;
13+
}
14+
15+
void loop()
16+
{
17+
for (uint16_t i = 0; i < FastLEDHub.numLeds; i++)
18+
{
19+
FastLEDHub.leds[i] = getCyclicColor((ledDiv * i + step) % (HSV2RGB_SMOOTH_RANGE * 2 / 3));
20+
}
21+
22+
step++;
23+
if (step == HSV2RGB_SMOOTH_RANGE * 2 / 3)
24+
step = 0;
25+
26+
FastLEDHub.delay(5);
27+
FastLEDHub.show();
28+
}
29+
30+
private:
31+
uint8_t ledDiv = 2.0 / 3 * HSV2RGB_SMOOTH_RANGE / FastLEDHub.numLeds;
32+
uint16_t step;
33+
34+
CRGB getCyclicColor(uint16_t index)
35+
{
36+
if (index < HSV2RGB_SMOOTH_RANGE * 1 / 3)
37+
{
38+
return hsv2rgb_smooth(HSV2RGB_SMOOTH_RANGE * 2 / 3 + index, FastLEDHub.getSlider("Saturation")->value, 255);
39+
}
40+
else
41+
{
42+
return hsv2rgb_smooth(HSV2RGB_SMOOTH_RANGE - (index - HSV2RGB_SMOOTH_RANGE * 1 / 3), FastLEDHub.getSlider("Saturation")->value, 255);
43+
}
44+
}
45+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <FastLEDHub.h>
4+
5+
class RgbWave : public Animation
6+
{
7+
public:
8+
using Animation::Animation;
9+
10+
uint8_t ledDiv = HSV2RGB_SMOOTH_RANGE / FastLEDHub.numLeds;
11+
uint16_t step;
12+
13+
void reset()
14+
{
15+
step = 0;
16+
}
17+
18+
void loop()
19+
{
20+
for (uint16_t i = 0; i < FastLEDHub.numLeds; i++)
21+
{
22+
FastLEDHub.leds[i] = hsv2rgb_smooth((ledDiv * i + step) % HSV2RGB_SMOOTH_RANGE, FastLEDHub.getSlider("Saturation")->value, 255);
23+
}
24+
25+
step++;
26+
if (step == HSV2RGB_SMOOTH_RANGE)
27+
step = 0;
28+
29+
FastLEDHub.delay(5);
30+
FastLEDHub.show();
31+
}
32+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <ESPEssentials.h>
2+
#include <FastLEDHub.h>
3+
4+
#include "Animations/rbWave.h"
5+
#include "Animations/rgbWave.h"
6+
7+
#define NUM_LEDS 100
8+
#define LIGHTSTRIP_PIN 5
9+
10+
void setup()
11+
{
12+
FastLEDHub.initialize("FastLEDHubExample", NUM_LEDS);
13+
FastLEDHub.addLeds<WS2812B, LIGHTSTRIP_PIN, GRB>(FastLEDHub.hardwareLeds, NUM_LEDS);
14+
FastLEDHub.registerAnimation(new RbWave("RB Wave"));
15+
FastLEDHub.registerAnimation(new RgbWave("RGB Wave"));
16+
FastLEDHub.registerSlider(new Slider("Saturation", 150, 255, 170, 1));
17+
}
18+
19+
void loop()
20+
{
21+
FastLEDHub.handle();
22+
}

0 commit comments

Comments
 (0)