Skip to content

Commit b255318

Browse files
committed
Update examples
1 parent 725e46d commit b255318

File tree

11 files changed

+278
-69
lines changed

11 files changed

+278
-69
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/// This animation has been taken from https://github.com/atuline/FastLED-Demos and
2+
/// modified to be used with FastLEDHub.
3+
/// It is licensed under the GNU General Public License v3.0.
4+
5+
#pragma once
6+
7+
#include <FastLEDHub.h>
8+
9+
extern CRGB leds[];
10+
11+
class Confetti : public Animation
12+
{
13+
public:
14+
using Animation::Animation;
15+
16+
uint8_t fade = 8;
17+
uint8_t inc = 1;
18+
uint8_t saturation = 100;
19+
uint8_t brightness = 255;
20+
int hue = 50;
21+
int hueDiff = 256;
22+
23+
void reset()
24+
{
25+
}
26+
27+
void loop()
28+
{
29+
uint8_t secondHand = (millis() / 1000) % 15;
30+
static uint8_t lastSecond = 99;
31+
if (lastSecond != secondHand)
32+
{
33+
lastSecond = secondHand;
34+
switch(secondHand)
35+
{
36+
case 0: inc = 1; hue = 192; saturation = 255; fade = 2; hueDiff = 256; break;
37+
case 5: inc = 2; hue = 128; fade = 8; hueDiff = 64; break;
38+
case 10: inc = 1; hue = random16(255); fade = 1; hueDiff = 16; break;
39+
case 15: break;
40+
}
41+
}
42+
43+
fadeToBlackBy(leds, FastLEDHub[0].size(), fade);
44+
int pos = random16(FastLEDHub[0].size());
45+
leds[pos] += CHSV((hue + random16(hueDiff))/4 , saturation, brightness);
46+
hue = hue + inc;
47+
48+
FastLEDHub.delay(5);
49+
FastLEDHub.show();
50+
}
51+
52+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <FastLEDHub.h>
4+
5+
extern CRGB leds[];
6+
7+
class Gradient : public Animation
8+
{
9+
public:
10+
using Animation::Animation;
11+
12+
uint16_t NUM_LEDS;
13+
14+
void reset()
15+
{
16+
NUM_LEDS = FastLEDHub[0].size();
17+
}
18+
19+
void loop()
20+
{
21+
for(uint16_t i = 0; i < NUM_LEDS; i++)
22+
{
23+
leds[i] = blend(FastLEDHub.getColorPicker(0)->value, FastLEDHub.getColorPicker(1)->value, 255 * i / NUM_LEDS);
24+
}
25+
26+
FastLEDHub.show();
27+
}
28+
};

examples/FastLEDHubExample/Animations/rgbWave.h renamed to examples/BasicExample/Animations/RGBWave.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include <FastLEDHub.h>
44

5-
class RgbWave : public Animation
5+
extern CRGB leds[];
6+
7+
class RGBWave : public Animation
68
{
79
public:
810
using Animation::Animation;
@@ -19,7 +21,7 @@ class RgbWave : public Animation
1921
{
2022
for (uint16_t i = 0; i < FastLEDHub.size(); i++)
2123
{
22-
FastLEDHub.leds()[i] = hsv2rgb_smooth((ledDiv * i + step) % HSV2RGB_SMOOTH_RANGE, FastLEDHub.getSlider("Saturation")->value, 255);
24+
leds[i] = hsv2rgb_smooth((ledDiv * i + step) % HSV2RGB_SMOOTH_RANGE, FastLEDHub.getSlider("Saturation")->value, 255);
2325
}
2426

2527
step++;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
#include <FastLEDHub.h>
4+
5+
extern CRGB leds[];
6+
7+
class Rainbow : public Animation
8+
{
9+
public:
10+
using Animation::Animation;
11+
12+
void reset()
13+
{
14+
}
15+
16+
void loop()
17+
{
18+
// Since we use beatsin88 to generate a sine wave we need to incorporate the speed slider without using delay():
19+
uint16_t speed = FastLEDHub.getSlider("Speed")->value;
20+
uint16_t startHue = beatsin16(speed / 16 / 5, 0, 1535);
21+
uint16_t endHue = beatsin16(speed / 16 / 2, 0, 1535);
22+
23+
if (startHue < endHue)
24+
{
25+
for(int16_t i = 0; i < FastLEDHub[0].size(); i++)
26+
{
27+
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
28+
}
29+
}
30+
else
31+
{
32+
for(int16_t i = FastLEDHub[0].size() - 1; i >= 0; i--)
33+
{
34+
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
35+
}
36+
}
37+
38+
FastLEDHub.show();
39+
}
40+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <FastLEDHub.h>
2+
3+
#include "Animations/Confetti.h"
4+
#include "Animations/Color.h"
5+
#include "Animations/Gradient.h"
6+
#include "Animations/Rainbow.h"
7+
#include "Animations/RGBWave.h"
8+
9+
#define NUM_LEDS 100
10+
#define LIGHTSTRIP_PIN 5
11+
#define LED_TYPE WS2812B
12+
13+
CRGB leds[NUM_LEDS];
14+
15+
void setup()
16+
{
17+
FastLEDHub.initialize("Basic Example");
18+
FastLEDHub.addLeds<LED_TYPE, LIGHTSTRIP_PIN, GRB>(leds, NUM_LEDS);
19+
20+
FastLEDHub.registerAnimation(new Color("Color"));
21+
FastLEDHub.registerAnimation(new Gradient("Gradient"));
22+
FastLEDHub.registerAnimation(new Rainbow("Rainbow"));
23+
FastLEDHub.registerAnimation(new RGBWave("RGB Wave"));
24+
FastLEDHub.registerAnimation(new Confetti("Confetti"));
25+
26+
FastLEDHub.registerSlider(new Slider("Saturation", 0, 255, 255, 1, "palette2"));
27+
28+
FastLEDHub.registerColorPicker(new ColorPicker("Primary Color", CRGB(255, 0, 0)));
29+
FastLEDHub.registerColorPicker(new ColorPicker("Secondary Color", CRGB(0, 255, 0)));
30+
}
31+
32+
void loop()
33+
{
34+
FastLEDHub.handle();
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <FastLEDHub.h>
4+
5+
extern CRGB leds[];
6+
7+
class Gradient : public Animation
8+
{
9+
public:
10+
using Animation::Animation;
11+
12+
uint16_t NUM_LEDS;
13+
14+
void reset()
15+
{
16+
NUM_LEDS = FastLEDHub[0].size();
17+
}
18+
19+
void loop()
20+
{
21+
for(uint16_t i = 0; i < NUM_LEDS; i++)
22+
{
23+
leds[i] = blend(FastLEDHub.getColorPicker(0)->value, FastLEDHub.getColorPicker(1)->value, 255 * i / NUM_LEDS);
24+
}
25+
26+
FastLEDHub.show();
27+
}
28+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <FastLEDHub.h>
2+
3+
#include <Animations/Color.h> // This animation comes with FastLEDHub
4+
#include "Animations/Gradient.h"
5+
6+
#define NUM_LEDS 100
7+
#define LIGHTSTRIP_PIN 5
8+
#define LED_TYPE WS2812B
9+
10+
CRGB leds[NUM_LEDS];
11+
12+
void setup()
13+
{
14+
FastLEDHub.initialize("Color Pickers Example");
15+
FastLEDHub.addLeds<LED_TYPE, LIGHTSTRIP_PIN, GRB>(leds, NUM_LEDS);
16+
17+
FastLEDHub.registerAnimation(new Color("Color"));
18+
FastLEDHub.registerAnimation(new Gradient("Gradient"));
19+
20+
FastLEDHub.registerColorPicker(new ColorPicker("Primary Color", CRGB(255, 0, 0)));
21+
FastLEDHub.registerColorPicker(new ColorPicker("Secondary Color", CRGB(255, 0, 0)));
22+
}
23+
24+
void loop()
25+
{
26+
FastLEDHub.handle();
27+
}

examples/FastLEDHubExample/Animations/rbWave.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/FastLEDHubExample/FastLEDHubExample.ino

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
#include <FastLEDHub.h>
4+
5+
extern CRGB leds[];
6+
7+
class Rainbow : public Animation
8+
{
9+
public:
10+
using Animation::Animation;
11+
12+
void reset()
13+
{
14+
}
15+
16+
void loop()
17+
{
18+
// Since we use beatsin88 to generate a sine wave we need to incorporate the speed slider without using delay():
19+
uint16_t speed = FastLEDHub.getSlider("Speed")->value;
20+
uint16_t startHue = beatsin16(speed / 16 / 5, 0, 1535);
21+
uint16_t endHue = beatsin16(speed / 16 / 2, 0, 1535);
22+
23+
if (startHue < endHue)
24+
{
25+
for(int16_t i = 0; i < FastLEDHub[0].size(); i++)
26+
{
27+
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
28+
}
29+
}
30+
else
31+
{
32+
for(int16_t i = FastLEDHub[0].size() - 1; i >= 0; i--)
33+
{
34+
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
35+
}
36+
}
37+
38+
FastLEDHub.show();
39+
}
40+
};

0 commit comments

Comments
 (0)