Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stnkl committed Apr 15, 2022
1 parent 725e46d commit b255318
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 69 deletions.
52 changes: 52 additions & 0 deletions examples/BasicExample/Animations/Confetti.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// This animation has been taken from https://github.com/atuline/FastLED-Demos and
/// modified to be used with FastLEDHub.
/// It is licensed under the GNU General Public License v3.0.

#pragma once

#include <FastLEDHub.h>

extern CRGB leds[];

class Confetti : public Animation
{
public:
using Animation::Animation;

uint8_t fade = 8;
uint8_t inc = 1;
uint8_t saturation = 100;
uint8_t brightness = 255;
int hue = 50;
int hueDiff = 256;

void reset()
{
}

void loop()
{
uint8_t secondHand = (millis() / 1000) % 15;
static uint8_t lastSecond = 99;
if (lastSecond != secondHand)
{
lastSecond = secondHand;
switch(secondHand)
{
case 0: inc = 1; hue = 192; saturation = 255; fade = 2; hueDiff = 256; break;
case 5: inc = 2; hue = 128; fade = 8; hueDiff = 64; break;
case 10: inc = 1; hue = random16(255); fade = 1; hueDiff = 16; break;
case 15: break;
}
}

fadeToBlackBy(leds, FastLEDHub[0].size(), fade);
int pos = random16(FastLEDHub[0].size());
leds[pos] += CHSV((hue + random16(hueDiff))/4 , saturation, brightness);
hue = hue + inc;

FastLEDHub.delay(5);
FastLEDHub.show();
}

};
28 changes: 28 additions & 0 deletions examples/BasicExample/Animations/Gradient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <FastLEDHub.h>

extern CRGB leds[];

class Gradient : public Animation
{
public:
using Animation::Animation;

uint16_t NUM_LEDS;

void reset()
{
NUM_LEDS = FastLEDHub[0].size();
}

void loop()
{
for(uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = blend(FastLEDHub.getColorPicker(0)->value, FastLEDHub.getColorPicker(1)->value, 255 * i / NUM_LEDS);
}

FastLEDHub.show();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <FastLEDHub.h>

class RgbWave : public Animation
extern CRGB leds[];

class RGBWave : public Animation
{
public:
using Animation::Animation;
Expand All @@ -19,7 +21,7 @@ class RgbWave : public Animation
{
for (uint16_t i = 0; i < FastLEDHub.size(); i++)
{
FastLEDHub.leds()[i] = hsv2rgb_smooth((ledDiv * i + step) % HSV2RGB_SMOOTH_RANGE, FastLEDHub.getSlider("Saturation")->value, 255);
leds[i] = hsv2rgb_smooth((ledDiv * i + step) % HSV2RGB_SMOOTH_RANGE, FastLEDHub.getSlider("Saturation")->value, 255);
}

step++;
Expand Down
40 changes: 40 additions & 0 deletions examples/BasicExample/Animations/Rainbow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <FastLEDHub.h>

extern CRGB leds[];

class Rainbow : public Animation
{
public:
using Animation::Animation;

void reset()
{
}

void loop()
{
// Since we use beatsin88 to generate a sine wave we need to incorporate the speed slider without using delay():
uint16_t speed = FastLEDHub.getSlider("Speed")->value;
uint16_t startHue = beatsin16(speed / 16 / 5, 0, 1535);
uint16_t endHue = beatsin16(speed / 16 / 2, 0, 1535);

if (startHue < endHue)
{
for(int16_t i = 0; i < FastLEDHub[0].size(); i++)
{
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
}
}
else
{
for(int16_t i = FastLEDHub[0].size() - 1; i >= 0; i--)
{
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
}
}

FastLEDHub.show();
}
};
35 changes: 35 additions & 0 deletions examples/BasicExample/BasicExample.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <FastLEDHub.h>

#include "Animations/Confetti.h"
#include "Animations/Color.h"
#include "Animations/Gradient.h"
#include "Animations/Rainbow.h"
#include "Animations/RGBWave.h"

#define NUM_LEDS 100
#define LIGHTSTRIP_PIN 5
#define LED_TYPE WS2812B

CRGB leds[NUM_LEDS];

void setup()
{
FastLEDHub.initialize("Basic Example");
FastLEDHub.addLeds<LED_TYPE, LIGHTSTRIP_PIN, GRB>(leds, NUM_LEDS);

FastLEDHub.registerAnimation(new Color("Color"));
FastLEDHub.registerAnimation(new Gradient("Gradient"));
FastLEDHub.registerAnimation(new Rainbow("Rainbow"));
FastLEDHub.registerAnimation(new RGBWave("RGB Wave"));
FastLEDHub.registerAnimation(new Confetti("Confetti"));

FastLEDHub.registerSlider(new Slider("Saturation", 0, 255, 255, 1, "palette2"));

FastLEDHub.registerColorPicker(new ColorPicker("Primary Color", CRGB(255, 0, 0)));
FastLEDHub.registerColorPicker(new ColorPicker("Secondary Color", CRGB(0, 255, 0)));
}

void loop()
{
FastLEDHub.handle();
}
28 changes: 28 additions & 0 deletions examples/ColorPickers/Animations/Gradient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <FastLEDHub.h>

extern CRGB leds[];

class Gradient : public Animation
{
public:
using Animation::Animation;

uint16_t NUM_LEDS;

void reset()
{
NUM_LEDS = FastLEDHub[0].size();
}

void loop()
{
for(uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = blend(FastLEDHub.getColorPicker(0)->value, FastLEDHub.getColorPicker(1)->value, 255 * i / NUM_LEDS);
}

FastLEDHub.show();
}
};
27 changes: 27 additions & 0 deletions examples/ColorPickers/ColorPickers.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <FastLEDHub.h>

#include <Animations/Color.h> // This animation comes with FastLEDHub
#include "Animations/Gradient.h"

#define NUM_LEDS 100
#define LIGHTSTRIP_PIN 5
#define LED_TYPE WS2812B

CRGB leds[NUM_LEDS];

void setup()
{
FastLEDHub.initialize("Color Pickers Example");
FastLEDHub.addLeds<LED_TYPE, LIGHTSTRIP_PIN, GRB>(leds, NUM_LEDS);

FastLEDHub.registerAnimation(new Color("Color"));
FastLEDHub.registerAnimation(new Gradient("Gradient"));

FastLEDHub.registerColorPicker(new ColorPicker("Primary Color", CRGB(255, 0, 0)));
FastLEDHub.registerColorPicker(new ColorPicker("Secondary Color", CRGB(255, 0, 0)));
}

void loop()
{
FastLEDHub.handle();
}
45 changes: 0 additions & 45 deletions examples/FastLEDHubExample/Animations/rbWave.h

This file was deleted.

22 changes: 0 additions & 22 deletions examples/FastLEDHubExample/FastLEDHubExample.ino

This file was deleted.

40 changes: 40 additions & 0 deletions examples/Sliders/Animations/Rainbow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <FastLEDHub.h>

extern CRGB leds[];

class Rainbow : public Animation
{
public:
using Animation::Animation;

void reset()
{
}

void loop()
{
// Since we use beatsin88 to generate a sine wave we need to incorporate the speed slider without using delay():
uint16_t speed = FastLEDHub.getSlider("Speed")->value;
uint16_t startHue = beatsin16(speed / 16 / 5, 0, 1535);
uint16_t endHue = beatsin16(speed / 16 / 2, 0, 1535);

if (startHue < endHue)
{
for(int16_t i = 0; i < FastLEDHub[0].size(); i++)
{
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
}
}
else
{
for(int16_t i = FastLEDHub[0].size() - 1; i >= 0; i--)
{
leds[i] = hsv2rgb_smooth(startHue + (endHue - startHue) * i / FastLEDHub[0].size(), FastLEDHub.getSlider("Saturation")->value, 255);
}
}

FastLEDHub.show();
}
};
24 changes: 24 additions & 0 deletions examples/Sliders/Sliders.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <FastLEDHub.h>

#include "Animations/Rainbow.h"

#define NUM_LEDS 100
#define LIGHTSTRIP_PIN 5
#define LED_TYPE WS2812B

CRGB leds[NUM_LEDS];

void setup()
{
FastLEDHub.initialize("Sliders Example");
FastLEDHub.addLeds<LED_TYPE, LIGHTSTRIP_PIN, GRB>(leds, NUM_LEDS);

FastLEDHub.registerAnimation(new Rainbow("Rainbow"));

FastLEDHub.registerSlider(new Slider("Saturation", 0, 255, 255, 1, "palette2"));
}

void loop()
{
FastLEDHub.handle();
}

0 comments on commit b255318

Please sign in to comment.