Skip to content

Instantly share code, notes, and snippets.

@kriegsman
Last active November 29, 2023 23:36
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kriegsman/964de772d64c502760e5 to your computer and use it in GitHub Desktop.
Save kriegsman/964de772d64c502760e5 to your computer and use it in GitHub Desktop.
Pride2015 - animated, ever-changing rainbows
#include "FastLED.h"
// Pride2015
// Animated, ever-changing rainbows.
// by Mark Kriegsman
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define DATA_PIN 3
//#define CLK_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 200
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
void setup() {
delay(3000); // 3 second delay for recovery
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection(TypicalLEDStrip)
.setDither(BRIGHTNESS < 255);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}
void loop()
{
pride();
FastLED.show();
}
// This function draws rainbows with an ever-changing,
// widely-varying set of parameters.
void pride()
{
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
static uint16_t sHue16 = 0;
uint8_t sat8 = beatsin88( 87, 220, 250);
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256;
uint16_t hueinc16 = beatsin88(113, 1, 3000);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
sHue16 += deltams * beatsin88( 400, 5,9);
uint16_t brightnesstheta16 = sPseudotime;
for( uint16_t i = 0 ; i < NUM_LEDS; i++) {
hue16 += hueinc16;
uint8_t hue8 = hue16 / 256;
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
CRGB newcolor = CHSV( hue8, sat8, bri8);
uint16_t pixelnumber = i;
pixelnumber = (NUM_LEDS-1) - pixelnumber;
nblend( leds[pixelnumber], newcolor, 64);
}
}
@wizbrewery
Copy link

nice, thank you for sharing

@kp99
Copy link

kp99 commented Mar 23, 2016

Beautiful Animation. Thanks for sharing.

@nbietz
Copy link

nbietz commented Jun 28, 2018

I would love to see your patterns, especially PRIDE, work with Christian Schwinne's (Aircoookie) WLED project (https://github.com/Aircoookie/WLED). Do you know of a way to easily port FastLed patterns to NeoPixel, or vice/versa? Thanks!

@jordanadania
Copy link

Incredible.

@garyjuergens
Copy link

Perfect. Awesome. Thank you.

@nagamaninhp
Copy link

one of my favorite animations..
i want to run the code with attiny85..
can anyone help me.?

@wcbearden
Copy link

I'm new to arduino coding and have very little experience but am trying to find something exactly like this but within set parameters of a palette (or 2 or 3). Is there a way to add some code to limit it from the Rainbow to a specific palette? Please and thanks. This sketch is beautiful!

@jordanadania
Copy link

I'm new to arduino coding and have very little experience but am trying to find something exactly like this but within set parameters of a palette (or 2 or 3). Is there a way to add some code to limit it from the Rainbow to a specific palette? Please and thanks. This sketch is beautiful!

I would guess that you could use the function ColorFromPalette and set the index parameter to the pride variable, hue8. That starts to sound like his other pattern, ColorWaves, though.

@jordanadania
Copy link

I'm new to arduino coding and have very little experience but am trying to find something exactly like this but within set parameters of a palette (or 2 or 3). Is there a way to add some code to limit it from the Rainbow to a specific palette? Please and thanks. This sketch is beautiful!

From his ColorWaves code...

https://gist.github.com/kriegsman/8281905786e8b2632aeb#file-colorwaveswithpalettes-ino-L119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment