diff --git a/examples/BasicExample/Animations/Confetti.h b/examples/BasicExample/Animations/Confetti.h new file mode 100644 index 0000000..b19dbcd --- /dev/null +++ b/examples/BasicExample/Animations/Confetti.h @@ -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 + +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(); + } + +}; diff --git a/examples/BasicExample/Animations/Gradient.h b/examples/BasicExample/Animations/Gradient.h new file mode 100644 index 0000000..af714f6 --- /dev/null +++ b/examples/BasicExample/Animations/Gradient.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +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(); + } +}; diff --git a/examples/FastLEDHubExample/Animations/rgbWave.h b/examples/BasicExample/Animations/RGBWave.h similarity index 69% rename from examples/FastLEDHubExample/Animations/rgbWave.h rename to examples/BasicExample/Animations/RGBWave.h index 7440f6e..87a545c 100644 --- a/examples/FastLEDHubExample/Animations/rgbWave.h +++ b/examples/BasicExample/Animations/RGBWave.h @@ -2,7 +2,9 @@ #include -class RgbWave : public Animation +extern CRGB leds[]; + +class RGBWave : public Animation { public: using Animation::Animation; @@ -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++; diff --git a/examples/BasicExample/Animations/Rainbow.h b/examples/BasicExample/Animations/Rainbow.h new file mode 100644 index 0000000..c230d4d --- /dev/null +++ b/examples/BasicExample/Animations/Rainbow.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +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(); + } +}; diff --git a/examples/BasicExample/BasicExample.ino b/examples/BasicExample/BasicExample.ino new file mode 100644 index 0000000..49dfef5 --- /dev/null +++ b/examples/BasicExample/BasicExample.ino @@ -0,0 +1,35 @@ +#include + +#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(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(); +} diff --git a/examples/ColorPickers/Animations/Gradient.h b/examples/ColorPickers/Animations/Gradient.h new file mode 100644 index 0000000..af714f6 --- /dev/null +++ b/examples/ColorPickers/Animations/Gradient.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +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(); + } +}; diff --git a/examples/ColorPickers/ColorPickers.ino b/examples/ColorPickers/ColorPickers.ino new file mode 100644 index 0000000..23d2ca4 --- /dev/null +++ b/examples/ColorPickers/ColorPickers.ino @@ -0,0 +1,27 @@ +#include + +#include // 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(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(); +} diff --git a/examples/FastLEDHubExample/Animations/rbWave.h b/examples/FastLEDHubExample/Animations/rbWave.h deleted file mode 100644 index 9b52df1..0000000 --- a/examples/FastLEDHubExample/Animations/rbWave.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include - -class RbWave : public Animation -{ -public: - using Animation::Animation; - - void reset() - { - step = 0; - } - - void loop() - { - for (uint16_t i = 0; i < FastLEDHub.size(); i++) - { - FastLEDHub.leds()[i] = getCyclicColor((ledDiv * i + step) % (HSV2RGB_SMOOTH_RANGE * 2 / 3)); - } - - step++; - if (step == HSV2RGB_SMOOTH_RANGE * 2 / 3) - step = 0; - - FastLEDHub.delay(5); - FastLEDHub.show(); - } - -private: - uint8_t ledDiv = 2.0 / 3 * HSV2RGB_SMOOTH_RANGE / FastLEDHub.size(); - uint16_t step; - - CRGB getCyclicColor(uint16_t index) - { - if (index < HSV2RGB_SMOOTH_RANGE * 1 / 3) - { - return hsv2rgb_smooth(HSV2RGB_SMOOTH_RANGE * 2 / 3 + index, FastLEDHub.getSlider("Saturation")->value, 255); - } - else - { - return hsv2rgb_smooth(HSV2RGB_SMOOTH_RANGE - (index - HSV2RGB_SMOOTH_RANGE * 1 / 3), FastLEDHub.getSlider("Saturation")->value, 255); - } - } -}; diff --git a/examples/FastLEDHubExample/FastLEDHubExample.ino b/examples/FastLEDHubExample/FastLEDHubExample.ino deleted file mode 100644 index c264a83..0000000 --- a/examples/FastLEDHubExample/FastLEDHubExample.ino +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#include "Animations/rbWave.h" -#include "Animations/rgbWave.h" - -#define NUM_LEDS 100 -#define LIGHTSTRIP_PIN 5 - -void setup() -{ - FastLEDHub.initialize("FastLEDHubExample", NUM_LEDS); - FastLEDHub.addLeds(FastLEDHub.hardwareLeds, NUM_LEDS); - FastLEDHub.registerAnimation(new RbWave("RB Wave")); - FastLEDHub.registerAnimation(new RgbWave("RGB Wave")); - FastLEDHub.registerSlider(new Slider("Saturation", 150, 255, 170, 1)); -} - -void loop() -{ - FastLEDHub.handle(); -} diff --git a/examples/Sliders/Animations/Rainbow.h b/examples/Sliders/Animations/Rainbow.h new file mode 100644 index 0000000..c230d4d --- /dev/null +++ b/examples/Sliders/Animations/Rainbow.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +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(); + } +}; diff --git a/examples/Sliders/Sliders.ino b/examples/Sliders/Sliders.ino new file mode 100644 index 0000000..fe7e1d6 --- /dev/null +++ b/examples/Sliders/Sliders.ino @@ -0,0 +1,24 @@ +#include + +#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(leds, NUM_LEDS); + + FastLEDHub.registerAnimation(new Rainbow("Rainbow")); + + FastLEDHub.registerSlider(new Slider("Saturation", 0, 255, 255, 1, "palette2")); +} + +void loop() +{ + FastLEDHub.handle(); +}