the twinkling is go

This commit is contained in:
Vivian Lim 2016-11-02 23:27:18 -07:00
parent 5a56fe2946
commit 9630723b66
1 changed files with 54 additions and 13 deletions

View File

@ -26,30 +26,71 @@
#include <platforms.h>
#include <power_mgt.h>
#include <Adafruit_NeoPixel.h>
#define PIN 0
#define NUM_LED 30
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LED, PIN, NEO_GRB + NEO_KHZ800);
#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[30];
CRGB leds[NUM_LED];
int saturation = 192;
int brightness = 96;
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, 0>(leds, 30);
FastLED.addLeds<NEOPIXEL, 0>(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() {
// a
static uint8_t hue = 0;
for (int i=0; i<30; i++)
for (int i=0; i<NUM_LED; i++)
{
int hueOffset = (240/30) * i;
leds[i] = CHSV((hue + hueOffset) % 255, saturation, brightness);
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]);
}
hue++;
FastLED.show();
//FastLED.showColor(CHSV(hue++, 255, 255));
clock++;
if (clock % HUE_RATE_MODULO == 0)
{
globalHue++;
}
delay(5);
}