97 lines
2.3 KiB
C++
97 lines
2.3 KiB
C++
#include <bitswap.h>
|
|
#include <chipsets.h>
|
|
#include <color.h>
|
|
#include <colorpalettes.h>
|
|
#include <colorutils.h>
|
|
#include <controller.h>
|
|
#include <cpp_compat.h>
|
|
#include <dmx.h>
|
|
#include <FastLED.h>
|
|
#include <fastled_config.h>
|
|
#include <fastled_delay.h>
|
|
#include <fastled_progmem.h>
|
|
#include <fastpin.h>
|
|
#include <fastspi.h>
|
|
#include <fastspi_bitbang.h>
|
|
#include <fastspi_dma.h>
|
|
#include <fastspi_nop.h>
|
|
#include <fastspi_ref.h>
|
|
#include <fastspi_types.h>
|
|
#include <hsv2rgb.h>
|
|
#include <led_sysdefs.h>
|
|
#include <lib8tion.h>
|
|
#include <noise.h>
|
|
#include <pixelset.h>
|
|
#include <pixeltypes.h>
|
|
#include <platforms.h>
|
|
#include <power_mgt.h>
|
|
|
|
#define PIN 0
|
|
#define NUM_LED 30
|
|
#define MIN_BRIGHTNESS 30
|
|
#define MAX_BRIGHTNESS 245
|
|
#define HUE_SPREAD 15
|
|
#define HUE_RATE_MODULO 96 // increasing this value makes the hue change slower
|
|
#define MIN_SATURATION 192
|
|
#define MAX_SATURATION 255
|
|
#define MIN_RATE 1
|
|
#define MAX_RATE 4
|
|
|
|
CRGB leds[NUM_LED];
|
|
|
|
byte clock = 0;
|
|
byte globalHue = 0;
|
|
byte hues[NUM_LED];
|
|
int brightnesses[NUM_LED];
|
|
int saturations[NUM_LED];
|
|
int rates[NUM_LED];
|
|
|
|
void setup() {
|
|
FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LED);
|
|
for (int i=0; i<NUM_LED; i++)
|
|
{
|
|
hues[i] = globalHue + random(0,HUE_SPREAD);
|
|
saturations[i] = random(MIN_SATURATION,MAX_SATURATION);
|
|
rates[i] = random(MIN_RATE,MAX_RATE);
|
|
brightnesses[i] = random(MIN_BRIGHTNESS,MAX_BRIGHTNESS);
|
|
}
|
|
}
|
|
|
|
void loop() {
|
|
for (int i=0; i<NUM_LED; i++)
|
|
{
|
|
brightnesses[i] += rates[i];
|
|
// Rate is positive but the new brightness is lower, so we overflowed.
|
|
if (brightnesses[i] >= MAX_BRIGHTNESS)
|
|
{
|
|
// Flip the sign of the rate & start decaying light.
|
|
rates[i] *= -1;
|
|
brightnesses[i] += rates[i];
|
|
}
|
|
// Rate is negative but the new brightness is bigger, so we underflowed.
|
|
else if (brightnesses[i] <= MIN_BRIGHTNESS)
|
|
{
|
|
// reset this pixel to a different color and start anew.
|
|
hues[i] = globalHue + random(0,HUE_SPREAD);
|
|
saturations[i] = random(MIN_SATURATION,MAX_SATURATION);
|
|
rates[i] = random(MIN_RATE,MAX_RATE);
|
|
brightnesses[i] = MIN_BRIGHTNESS;
|
|
}
|
|
else
|
|
{
|
|
brightnesses[i] += rates[i];
|
|
}
|
|
|
|
leds[i] = CHSV(hues[i], saturations[i], brightnesses[i]);
|
|
}
|
|
FastLED.show();
|
|
|
|
clock++;
|
|
if (clock % HUE_RATE_MODULO == 0)
|
|
{
|
|
globalHue++;
|
|
}
|
|
|
|
delay(5);
|
|
}
|