Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<FastLED.h>
- #define LED_PIN_A 3
- #define LED_PIN_B 5
- #define LED_PIN_C 6
- #define LED_PIN_D 9
- #define FRAME_ADV_PIN 12
- #define ANIMATION_ADV_PIN 4
- #define BRIGHTNESS 255
- #define LED_TYPE WS2812
- #define COLOR_ORDER GRB
- #define NUM_STRIPS 4
- #define MINUTES_SPEED 1
- const boolean isTriggered = false;
- const uint8_t kMatrixWidth = 16;
- const uint8_t kMatrixHeight = 16; // Must be divisible by NUM_STRIPS (4)
- const uint8_t ledsPerStrip = kMatrixWidth * kMatrixHeight / NUM_STRIPS;
- const boolean kMatrixSerpentineLayout = true;
- #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
- #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
- CRGB leds[kMatrixWidth * kMatrixHeight];
- uint8_t mainHue = 128; // Reference hue for color combinations
- // NOTE: 30 degrees on the color wheel is 21.3 on 8-bit hue
- // Timing controls
- int refreshRate = 60; // Hz // Refresh rate of the LEDs independent of counters
- long refreshIncrement = 1000 / refreshRate; // Refresh rate in milliseconds
- long previousMillis = 0; // will store last time LEDs were updated
- uint8_t count8 = 0;
- uint8_t countMode = 1;
- uint16_t countMinutes = 0;
- boolean modeButtonState = false;
- uint8_t countPalette = 0; // Count which palette to animate from
- uint8_t offsetPalette = 0; // index offset for when we fill from palette
- // This example combines two features of FastLED to produce a remarkable range of
- // effects from a relatively small amount of code. This example combines FastLED's
- // color palette lookup functions with FastLED's Perlin/simplex noise generator, and
- // the combination is extremely powerful.
- //
- // You might want to look at the "ColorPalette" and "Noise" examples separately
- // if this example code seems daunting.
- //
- //
- // The basic setup here is that for each frame, we generate a new array of
- // 'noise' data, and then map it onto the LED matrix through a color palette.
- //
- // Periodically, the color palette is changed, and new noise-generation parameters
- // are chosen at the same time. In this example, specific noise-generation
- // values have been selected to match the given color palettes; some are faster,
- // or slower, or larger, or smaller than others, but there's no reason these
- // parameters can't be freely mixed-and-matched.
- //
- // In addition, this example includes some fast automatic 'data smoothing' at
- // lower noise speeds to help produce smoother animations in those cases.
- //
- // The FastLED built-in color palettes (Forest, Clouds, Lava, Ocean, Party) are
- // used, as well as some 'hand-defined' ones, and some proceedurally generated
- // palettes.
- // The 16 bit version of our coordinates
- static uint16_t x;
- static uint16_t y;
- static uint16_t z;
- // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
- // use the z-axis for "time". speed determines how fast time moves forward. Try
- // 1 for a very slow moving effect, or 60 for something that ends up looking like
- // water.
- uint16_t speed = 1; // speed is set dynamically once we've started up
- // Scale determines how far apart the pixels in our noise matrix are. Try
- // changing these values around to see how it affects the motion of the display. The
- // higher the value of scale, the more "zoomed out" the noise iwll be. A value
- // of 1 will be so zoomed in, you'll mostly see solid colors.
- uint16_t scale = 80; // scale is set dynamically once we've started up
- // This is the array that we keep our computed noise values in
- uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
- CRGBPalette16 currentPalette( CRGB::Black );
- TBlendType currentBlending;
- uint8_t colorLoop = 1;
- void setup() {
- delay(3000);
- // Construct the LED matrix from multiple strips
- // tell FastLED there's 60 leds on pin A, starting at index 0 in the led array
- FastLED.addLeds<LED_TYPE, LED_PIN_A, GRB>(leds, 0, ledsPerStrip);
- // tell FastLED there's 60 NEOPIXEL leds on pin 11, starting at index 60 in the led array
- FastLED.addLeds<LED_TYPE, LED_PIN_B, GRB>(leds, ledsPerStrip, ledsPerStrip);
- // tell FastLED there's 60 NEOPIXEL leds on pin 12, starting at index 120 in the led array
- FastLED.addLeds<LED_TYPE, LED_PIN_C, GRB>(leds, 2 * ledsPerStrip, ledsPerStrip);
- // tell FastLED there's 60 NEOPIXEL leds on pin 12, starting at index 120 in the led array
- FastLED.addLeds<LED_TYPE, LED_PIN_D, GRB>(leds, 3 * ledsPerStrip, ledsPerStrip);
- //LEDS.addLeds<LED_TYPE,LED_PIN_A,COLOR_ORDER>(leds,NUM_LEDS);
- LEDS.setBrightness(BRIGHTNESS);
- currentBlending = BLEND;
- // Initialize our coordinates to some random values
- x = random16();
- y = random16();
- z = random16();
- Serial.begin(9600); // Serial Baudrate
- pinMode(FRAME_ADV_PIN, INPUT);
- pinMode(ANIMATION_ADV_PIN, INPUT);
- if (isTriggered == true) {
- while (digitalRead(FRAME_ADV_PIN) < 1) {
- SetupSunnyCloudsPalette();
- fillnoise8();
- mapNoiseToLEDsUsingPalette();
- LEDS.show();
- }
- }
- }
- void loop() {
- // Update the LEDs with the designated refresh rate
- unsigned long currentMillis = millis();
- if (isTriggered == true) {
- // Update when triggered and wait a bit before triggering again
- if(currentMillis - previousMillis > 2000L && digitalRead(FRAME_ADV_PIN) > 0) {
- updateAnimations(currentMillis);
- }
- } else {
- // Continuously update with the refresh rate
- if(currentMillis - previousMillis > refreshRate) {
- updateAnimations(currentMillis);
- }
- }
- // delay(10);
- }
- void updateAnimations(unsigned long currentMillis) {
- for (int updatenum = 0; updatenum < 5; updatenum++) {
- // Update the main 8-bit counnter
- //count8 = (millis() / 20) % 256;
- count8 += 1;
- //if (count8 % 256 == 0) {countMode += 1;}
- countMinutes = (countMinutes + MINUTES_SPEED) % 5760;
- // Update the refresh rate counter
- previousMillis = currentMillis;
- // Periodically choose a new palette, speed, and scale
- ChangePaletteAndSettingsPeriodically();
- // generate noise data slower than the default allows
- fillnoise8();
- // convert the noise data to colors in the LED array
- // using the current palette
- if ((count8 % 500) == 0 ) {offsetPalette+=1;}
- mapNoiseToLEDsUsingPalette();
- //FillLEDsFromPaletteColors( count8 );
- LEDS.show();
- }
- }
- // Fill the x/y array of 8-bit noise values using the inoise8 function.
- void fillnoise8() {
- // If we're runing at a low "speed", some 8-bit artifacts become visible
- // from frame-to-frame. In order to reduce this, we can do some fast data-smoothing.
- // The amount of data smoothing we're doing depends on "speed".
- uint8_t dataSmoothing = 0;
- if( speed < 50) {
- dataSmoothing = 200 - (speed * 4);
- }
- for(int i = 0; i < MAX_DIMENSION; i++) {
- int ioffset = scale * i;
- for(int j = 0; j < MAX_DIMENSION; j++) {
- int joffset = scale * j;
- uint8_t data = inoise8(x + ioffset,y + joffset,z);
- // The range of the inoise8 function is roughly 16-238.
- // These two operations expand those values out to roughly 0..255
- // You can comment them out if you want the raw noise data.
- data = qsub8(data,16);
- data = qadd8(data,scale8(data,39));
- if( dataSmoothing ) {
- uint8_t olddata = noise[i][j];
- uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
- data = newdata;
- }
- noise[i][j] = data;
- }
- }
- z += speed;
- // apply slow drift to X and Y, just for visual variation.
- x += speed / 8;
- y -= speed / 16;
- }
- void mapNoiseToLEDsUsingPalette()
- {
- static uint8_t ihue=0;
- for(int i = 0; i < kMatrixWidth; i++) {
- for(int j = 0; j < kMatrixHeight; j++) {
- // We use the value at the (i,j) coordinate in the noise
- // array for our brightness, and the flipped value from (j,i)
- // for our pixel's index into the color palette.
- uint8_t index = noise[j][i];
- uint8_t bri = noise[i][j];
- // if this palette is a 'loop', add a slowly-changing base value
- if( colorLoop) {
- index += offsetPalette;
- }
- // brighten up, as the color palette itself often contains the
- // light/dark dynamic range desired
- if( bri > 127 ) {
- bri = 255;
- } else {
- bri = dim8_raw( bri * 2);
- }
- CRGB color = ColorFromPalette( currentPalette, index, bri);
- leds[XY(i,j)] = color;
- }
- }
- ihue+=1;
- }
- void FillLEDsFromPaletteColors( uint8_t colorIndex)
- {
- uint8_t brightness = 255;
- for( int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
- colorIndex += 3;
- }
- }
- // There are several different palettes of colors demonstrated here.
- //
- // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
- // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
- //
- // Additionally, you can manually define your own color palettes, or you can write
- // code that creates color palettes on the fly.
- // 1 = 5 sec per palette
- // 2 = 10 sec per palette
- // etc
- #define HOLD_PALETTES_X_TIMES_AS_LONG 4
- void ChangePaletteAndSettingsPeriodically()
- {
- //static uint8_t lastSecond = 99;
- //uint8_t secondHand = ((millis() / 1000) / HOLD_PALETTES_X_TIMES_AS_LONG) % 60;
- // Set up a counter to move the reference hue for rainbow animations
- //if ((count8 % 1) == 0) {countPalette += 1; secondHand -= (secondHand % 5); lastSecond = 99;}
- //if ((countPalette % 256) == 0) {countPalette += 1; secondHand -= (secondHand % 5); lastSecond = 99;}
- // Manually set the Noise pattern to override te demo loop temporarily
- //secondHand = 5;
- countPalette = count8;
- if (digitalRead(ANIMATION_ADV_PIN) == HIGH && modeButtonState == false) {
- countMode = (countMode + 1) % 12;
- modeButtonState = true;
- } else if (digitalRead(ANIMATION_ADV_PIN) == LOW) {
- modeButtonState = false;
- }
- // Demo code to run different animations in sequence
- if( 4 != 5) {
- //lastSecond = secondHand;
- if( countMode == 0) { SetupSunrisePalette(countPalette); speed = 1; scale =120; colorLoop = 0; }
- if( countMode == 1) { SetupSunnyCloudsPalette(); speed = 1; scale =120; colorLoop = 0; }
- if( countMode == 2) { SetupSunsetPalette(countPalette); speed = 1; scale =120; colorLoop = 0; }
- if( countMode == 3) { SetupMoonlightPalette(countPalette); speed = 1; scale =120; colorLoop = 0; }
- if( countMode == 4) { SetupAnalogousPalette(countPalette); speed = 5; scale = 80; colorLoop = 0; }
- if( countMode == 5) { SetupComplementaryPalette(countPalette); speed = 3; scale =300; colorLoop = 0; }
- if( countMode == 6) { SetupSplitComplementaryPalette(countPalette); speed = 4; scale = 30; colorLoop = 0; }
- if( countMode == 7) { SetupDoubleComplementaryPalette(countPalette); speed = 4; scale = 50; colorLoop = 0; }
- if( countMode == 8) { SetupTriadicPalette(countPalette); speed = 2; scale = 90; colorLoop = 0; }
- if( countMode == 9) { AnimateWeatherPalette(); speed = 1; scale =120; colorLoop = 0; }
- if( countMode == 10) { SetupNeoPalette(); speed = 8; scale =120; colorLoop = 1; }
- if( countMode == 11) { SetupBlackPalette(); speed = 30; scale = 80; colorLoop = 0; }
- }
- }
- /*
- Weather Patterns
- The goal here is to illuminate the clouds in the foreground
- and the sky in the background differently thoughout the day.
- There are 24*60=1440 minutes per 24hr day,
- so we animate a time lapse with 0.25 minutes per frame
- for a total of 5760 frames. That's 96 seconds at 60fps.
- There are 240 frames per hour in 4 seconds at 60fps.
- Minutes 0 to 600 - Sunrise
- As the sun rises, the sky is dark and the clouds illuminate with yellow
- The sky fades in to pale blue and then deepens in saturation
- as the clouds fade to dim and then bright white
- Minutes 601 to 2400 - Daytime
- The day is represented with white clouds on a deep blue sky,
- but as the day gets cloudier, the sky darkens into a thunderstorm.
- Thuderstorms are rendered the same during the day as they are at night.
- Minutes 2401 to 3000 - Sunset
- If the day is only cloudy and not storming,
- the sun turns the clouds pink and purple as it sets
- and the sky deepens and slowly darkens.
- Minutes 3001 to 5760 - Moonlight
- The clouds are dimly lit by the moon and the sky is black
- */
- CRGBPalette16 targetPalette( CRGB::Black );
- uint8_t maxChanges = 36;
- uint8_t cloudiness = 130;
- void AnimateWeatherPalette()
- {
- static uint8_t cloudSaturation = 0;
- static uint8_t skySaturation = 230;
- // First, test the cloudiness.
- // If it's over 192, then animate a thunderstorm
- if (cloudiness >= 192) {
- // There is a thunderstorm of 0-63 in severity
- // Severity causes the clouds to darken
- // and the lightning to strike more frequently
- } else {
- // There are 0-15 clouds evenly dispersed across the sky
- // --- Sunrise ---
- // Black out the sky before sunrise
- //if (countMinutes == 0) { currentPalette = CRGBPalette16( CRGB::Black ); }
- // Golden sunrise clouds sky cloudRandomness
- if (countMinutes == 3) { SetupWeatherPalette(CHSV( 30,230,140),CHSV( 40,230,120), 40); }
- // Bring down the sky and keep brightening the clouds
- if (countMinutes == 200) { SetupWeatherPalette(CHSV( 30,230,200),CHSV( 40,230, 0), 40); }
- if (countMinutes == 220) { SetupWeatherPalette(CHSV( 40,230,200),CHSV(160,230, 0), 30); }
- // Bring up the sky in blue as the clouds fade back out
- if (countMinutes == 300) { SetupWeatherPalette(CHSV( 50,230, 90),CHSV(160,230, 90), 30); }
- // Keep bringing up the sky and clouds and bring the clouds to white
- if (countMinutes == 400) { SetupWeatherPalette(CHSV( 50, 0,192),CHSV(160,230,192), 30); }
- if (countMinutes == 500) { SetupWeatherPalette(CHSV( 90, 0,192),CHSV(160,230,200), 30); }
- if (countMinutes == 600) { SetupWeatherPalette(CHSV(245, 0,220),CHSV(160,230,200), 30); }
- // --- Sunset ---
- if (countMinutes ==2400) { SetupWeatherPalette(CHSV(245, 90,220),CHSV(160,240,190), 30); }
- if (countMinutes ==2500) { SetupWeatherPalette(CHSV(245,120,200),CHSV(160,240,180), 30); }
- if (countMinutes ==2700) { SetupWeatherPalette(CHSV(245,230,150),CHSV(160,240,150), 30); }
- if (countMinutes ==2900) { SetupWeatherPalette(CHSV(245,230, 0),CHSV(160,240, 0), 30); }
- // --- Moonlight ---
- if (countMinutes ==3100) { SetupWeatherPalette(CHSV(245, 0, 0),CHSV(160, 0, 0), 30); }
- if (countMinutes ==3300) { SetupWeatherPalette(CHSV(245, 0,120),CHSV(160, 0, 50), 30); }
- if (countMinutes ==5600) { SetupWeatherPalette(CHSV(245, 0,0),CHSV(160, 0, 0), 30); }
- }
- // Slow the rate that the palettes are blending, but let them blend evenly
- if ((countMinutes / MINUTES_SPEED) % 6 == 0) { nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);}
- }
- void SetupWeatherPalette(CHSV cloudColor, CHSV skyColor, uint8_t cloudRandomness)
- {
- for (int i = 0; i < 16; i++) {
- if (i >= cloudiness / 16) {
- // Apply sky color
- targetPalette[i] = skyColor;
- } else {
- // Apply cloud color and some randomization
- targetPalette[i] = CHSV( cloudColor.hue, cloudColor.saturation, cloudColor.value);
- //targetPalette[i].hue += random8(cloudRandomness);
- }
- }
- }
- void SetupSunnyCloudsPalette()
- {
- static uint8_t cloudSaturation = 0;
- static uint8_t skySaturation = 230;
- if (cloudiness <= 127) {
- cloudSaturation = 255-cloudiness*1.9;
- skySaturation = 230;
- } else {
- cloudSaturation = 0;
- skySaturation = 230-(cloudiness-127)*1.7;
- }
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CHSV( 160, skySaturation, 255-cloudiness/2 ) );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[1] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[2] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[3] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[4] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[5] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[6] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[7] = CHSV( 160, cloudSaturation, 255 );
- /*
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[1] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[4] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[5] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[8] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[9] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[12] = CHSV( 160, cloudSaturation, 255 );
- currentPalette[13] = CHSV( 160, cloudSaturation, 255 );
- */
- }
- void SetupSunsetPalette(uint8_t time)
- {
- static uint8_t skyBrightness = 255;
- static uint8_t cloudBrightness = 255;
- if ( time <= 201) {
- // The sun is setting, but still out
- cloudBrightness = 255;
- skyBrightness = 255- time/2;
- } else {
- // The sun sinks beneath the horizon
- cloudBrightness = 256-( time-200)*4.6;
- skyBrightness = 180-( time-200)*3;
- }
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CHSV( 160, 255, skyBrightness ) );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[1] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[4] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[5] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[8] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[9] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[12] = CHSV( 245+random8(30), time, cloudBrightness );
- currentPalette[13] = CHSV( 245+random8(30), time, cloudBrightness );
- }
- void SetupSunrisePalette(uint8_t time)
- {
- static uint8_t skyBrightness = 0;
- static uint8_t cloudBrightness = 0;
- static uint8_t skySaturation = 255;
- if ( time <= 50) {
- // Before the sun rises
- cloudBrightness = time*4.6;
- skyBrightness = 0;
- skySaturation = 180;
- colorLoop = 0;
- speed = 1;
- } else if ( time <= 100){
- // The Sky is changing colors
- skyBrightness = ( time-50)*4.6;
- cloudBrightness = 230-(( time-50)*1.6);
- skySaturation = 200;
- colorLoop = 1;
- speed = 1;
- } else {
- // Sunrise into day
- cloudBrightness = (( time-10)*1);
- skyBrightness = 240;
- skySaturation = 220;
- speed = 3;
- }
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CHSV( 160, skySaturation, skyBrightness ) );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[1] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[4] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[5] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[8] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[9] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[12] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- currentPalette[13] = CHSV( 60+random8(10), 256- time, cloudBrightness );
- }
- void SetupMoonlightPalette(uint8_t time)
- {
- static uint8_t cloudBrightness = 0;
- if ( time <= 50) {
- // Darkness before moonlight
- cloudBrightness = time*3;
- } else if ( time <= 200){
- // Clouds and moonlight
- cloudBrightness = 150;
- } else {
- // Fade out before sunrise
- cloudBrightness = 150-( time-200)*2.6;
- }
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CHSV( 160, 0, 0 ) );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[1] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[4] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[5] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[8] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[9] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[12] = CHSV( 60+random8(10), 0, cloudBrightness );
- currentPalette[13] = CHSV( 60+random8(10), 0, cloudBrightness );
- }
- /*
- Color Harmony Patterns
- We've found these useful for trying out and thinking about different color combinations.
- They are based on ideas about which colors may be pleasing in combinations.
- Of course, this isn't an exact science, so we want to play with brightness and saturation
- and some randomization on hue as well.
- */
- void SetupAnalogousPalette(uint8_t referenceHue)
- {
- // Set all 16 palette entries to reference
- fill_solid( currentPalette, 16, CHSV( referenceHue, 255, 127 ) );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( referenceHue-21, 180, 255 );
- currentPalette[1] = CHSV( referenceHue, 255, 255 );
- currentPalette[2] = CHSV( referenceHue+21, 180, 255 );
- currentPalette[6] = CHSV( referenceHue+21, 255, 255 );
- currentPalette[7] = CHSV( referenceHue, 180, 255 );
- currentPalette[8] = CHSV( referenceHue-21, 255, 255 );
- currentPalette[11] = CHSV( referenceHue+21, 180, 255 );
- currentPalette[12] = CHSV( referenceHue-21, 255, 255 );
- currentPalette[13] = CHSV( referenceHue+21, 180, 255 );
- }
- void SetupComplementaryPalette(uint8_t referenceHue)
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CRGB::Black );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( referenceHue, 255, 255 );
- currentPalette[1] = CHSV( referenceHue, 255, 255 );
- currentPalette[4] = CHSV( referenceHue+128, 255, 255 );
- currentPalette[5] = CHSV( referenceHue+128, 255, 255 );
- currentPalette[8] = CHSV( referenceHue, 200, 255 );
- currentPalette[9] = CHSV( referenceHue, 200, 255 );
- currentPalette[12] = CHSV( referenceHue+128, 200, 255 );
- currentPalette[13] = CHSV( referenceHue+128, 200, 255 );
- }
- void SetupSplitComplementaryPalette(uint8_t referenceHue)
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CRGB::Black );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( referenceHue-21, 180, 255 );
- currentPalette[1] = CHSV( referenceHue-21, 255, 255 );
- currentPalette[2] = CHSV( referenceHue-21, 127, 255 );
- currentPalette[4] = CHSV( referenceHue+128, 255, 255 );
- currentPalette[6] = CHSV( referenceHue+21, 255, 255 );
- currentPalette[7] = CHSV( referenceHue+21, 127, 255 );
- currentPalette[8] = CHSV( referenceHue+21, 255, 255 );
- currentPalette[10] = CHSV( referenceHue+128, 180, 255 );
- currentPalette[12] = CHSV( referenceHue+21, 180, 255 );
- currentPalette[13] = CHSV( referenceHue-21, 150, 255 );
- currentPalette[14] = CHSV( referenceHue+128, 255, 255 );
- }
- void SetupDoubleComplementaryPalette(uint8_t referenceHue)
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CRGB::Black );
- // 30 degrees on color wheel is about 21.3 out of 256
- currentPalette[0] = CHSV( referenceHue, 255, 255 );
- currentPalette[2] = CHSV( referenceHue, 150, 255 );
- currentPalette[4] = CHSV( referenceHue+128, 255, 255 );
- currentPalette[6] = CHSV( referenceHue+128, 150, 255 );
- currentPalette[8] = CHSV( referenceHue+43, 200, 255 );
- currentPalette[10] = CHSV( referenceHue+43, 150, 255 );
- currentPalette[12] = CHSV( referenceHue+171, 200, 255 );
- currentPalette[14] = CHSV( referenceHue+171, 150, 255 );
- }
- void SetupTriadicPalette(uint8_t referenceHue)
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CRGB::Black );
- // A third around the color wheel is 85 out of 256
- currentPalette[0] = CHSV( referenceHue-85, 200, 255 );
- currentPalette[1] = CHSV( referenceHue-85, 255, 255 );
- currentPalette[2] = CHSV( referenceHue-85, 200, 255 );
- currentPalette[6] = CHSV( referenceHue+85, 255, 255 );
- currentPalette[7] = CHSV( referenceHue+85, 200, 255 );
- currentPalette[8] = CHSV( referenceHue+85, 255, 255 );
- currentPalette[11] = CHSV( referenceHue, 200, 255 );
- currentPalette[12] = CHSV( referenceHue, 255, 255 );
- currentPalette[13] = CHSV( referenceHue, 200, 255 );
- }
- // This function generates a random palette that's a gradient
- // between four different colors. The first is a dim hue, the second is
- // a bright hue, the third is a bright pastel, and the last is
- // another bright hue. This gives some visual bright/dark variation
- // which is more interesting than just a gradient of different hues.
- void SetupRandomPalette(uint8_t referenceHue)
- {
- currentPalette = CRGBPalette16(
- CHSV( referenceHue, 255, 90),
- CHSV( referenceHue+40, 255, 255),
- CHSV( referenceHue+128, 150, 255),
- CHSV( referenceHue+168, 255, 255));
- }
- void SetupNeoPalette()
- {
- currentPalette = CRGBPalette16(
- CHSV( 96, 255, 0),
- CHSV( 96, 255, 255),
- CHSV( 96, 180, 0),
- CHSV( 96, 255, 128));
- }
- void SetupLightCyclePalette()
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CRGB::Black);
- // and set every fourth one to white.
- currentPalette[0] = CHSV( 32, 255, 255);
- currentPalette[4] = CHSV( 132, 255, 255);
- currentPalette[8] = CHSV( 32, 230, 255);
- currentPalette[12] = CHSV( 132, 230, 255);
- }
- void SetupBlackPalette()
- {
- // 'black out' all 16 palette entries...
- fill_solid( currentPalette, 16, CRGB::Black);
- }
- //
- // Mark's xy coordinate mapping code. See the XYMatrix for more information on it.
- //
- uint16_t XY( uint8_t x, uint8_t y)
- {
- uint16_t i;
- if( kMatrixSerpentineLayout == false) {
- i = (y * kMatrixWidth) + x;
- }
- if( kMatrixSerpentineLayout == true) {
- if( y & 0x01) {
- // Odd rows run backwards
- uint8_t reverseX = (kMatrixWidth - 1) - x;
- i = (y * kMatrixWidth) + reverseX;
- } else {
- // Even rows run forwards
- i = (y * kMatrixWidth) + x;
- }
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement