From b29d42255070822e8173be03fbff1a0dc9c92937 Mon Sep 17 00:00:00 2001 From: firepixie Date: Tue, 28 May 2024 16:18:32 -0700 Subject: [PATCH 1/2] Create designer_palettes_sunset.ino --- .../designer_palettes_sunset.ino | 298 ++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino diff --git a/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino b/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino new file mode 100644 index 000000000..5bc2c3b98 --- /dev/null +++ b/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino @@ -0,0 +1,298 @@ + +#include "FastLED.h" + +// ColorWavesWithPalettes +// Animated shifting color waves, with several cross-fading color palettes. +// by Mark Kriegsman, August 2015 +// +// Color palettes courtesy of cpt-city and its contributors: +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ +// +// Color palettes converted for FastLED using "PaletteKnife" v1: +// http://fastled.io/tools/paletteknife/ +// + + +#define DATA_PIN SCL +#define LED_TYPE WS2812 +#define COLOR_ORDER RBG // If colors are coming out wrong, re-order (RGB, BRG, etc) +#define NUM_LEDS 150 // Change this to reflect the number of LEDs you have +#define BRIGHTNESS 255 // Set Brightness here + +CRGB leds[NUM_LEDS]; + +// ten seconds per color palette makes a good demo +// 20-120 is better for deployment +#define SECONDS_PER_PALETTE 30 + + +void setup() { + delay(1000); // 3 second delay for recovery + + // tell FastLED about the LED strip configuration + FastLED.addLeds(leds, NUM_LEDS) + .setCorrection(TypicalLEDStrip) // cpt-city palettes have different color balance + .setDither(BRIGHTNESS < 255); + + // set master brightness control + FastLED.setBrightness(BRIGHTNESS); +} + +// Forward declarations of an array of cpt-city gradient palettes, and +// a count of how many there are. The actual color palette definitions +// are at the bottom of this file. +extern const TProgmemRGBGradientPalettePtr gGradientPalettes[]; +extern const uint8_t gGradientPaletteCount; + +// Current palette number from the 'playlist' of color palettes +uint8_t gCurrentPaletteNumber = 0; + +CRGBPalette16 gCurrentPalette( CRGB::Black); +CRGBPalette16 gTargetPalette( gGradientPalettes[0] ); + + + + +// This function draws color waves with an ever-changing, +// widely-varying set of parameters, using a color palette. +void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette) +{ + 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, 225, 255); + 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, 300, 1500); + + 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 < numleds; i++) { + hue16 += hueinc16; + uint8_t hue8 = hue16 / 256; + uint16_t h16_128 = hue16 >> 7; + if( h16_128 & 0x100) { + hue8 = 255 - (h16_128 >> 1); + } else { + hue8 = h16_128 >> 1; + } + + 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); + + uint8_t index = hue8; + //index = triwave8( index); + index = scale8( index, 240); + + CRGB newcolor = ColorFromPalette( palette, index, bri8); + + uint16_t pixelnumber = i; + pixelnumber = (numleds-1) - pixelnumber; + + nblend( ledarray[pixelnumber], newcolor, 128); + } +} + +// Alternate rendering function just scrolls the current palette +// across the defined LED strip. +void palettetest( CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette) +{ + static uint8_t startindex = 0; + startindex--; + fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND); +} + +// Gradient palette "bhw1_01_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_01.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 12 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw1_01_gp ) { + 0, 227,101, 3, + 117, 194, 18, 19, + 255, 92, 8,192}; + + // Gradient palette "bhw1_07_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_07.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 8 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw1_07_gp ) { + 0, 232, 65, 1, + 255, 229,227, 1}; + + // Gradient palette "bhw1_sunset3_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_sunset3.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 28 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw1_sunset3_gp ) { + 0, 227,237, 56, + 33, 186, 67, 1, + 71, 163, 21, 1, + 81, 157, 13, 1, + 188, 39, 21, 18, + 234, 12, 7, 4, + 255, 12, 7, 4}; + +// Gradient palette "bhw1_sunset2_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_sunset2.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 20 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw1_sunset2_gp ) { + 0, 255,175, 8, + 81, 237, 29, 10, + 137, 148, 57, 42, + 165, 68, 54, 54, + 255, 18, 23, 29}; + +// Gradient palette "bhw2_sherbet2_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_sherbet2.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 32 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_sherbet2_gp ) { + 0, 217, 1, 1, + 35, 249, 43, 19, + 71, 247,125,172, + 109, 206, 2, 32, + 163, 210, 23, 9, + 211, 255,255,255, + 232, 252,199, 88, + 255, 206,115, 52}; + +// Gradient palette "bhw2_39_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_39.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 28 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_39_gp ) { + 0, 2,184,188, + 33, 56, 27,162, + 66, 56, 27,162, + 122, 255,255, 45, + 150, 227, 65, 6, + 201, 67, 13, 27, + 255, 16, 1, 53}; + +// Gradient palette "bhw2_sunsetx_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_sunsetx.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 36 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_sunsetx_gp ) { + 0, 42, 55,255, + 25, 73,101,242, + 89, 115,162,228, + 107, 115,162,228, + 114, 100, 77,201, + 127, 86, 23,174, + 142, 190, 32, 24, + 171, 210,107, 42, + 255, 232,229, 67}; + +// Gradient palette "bhw2_xc_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xc.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 28 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_xc_gp ) { + 0, 4, 2, 9, + 58, 16, 0, 47, + 122, 24, 0, 16, + 158, 144, 9, 1, + 183, 179, 45, 1, + 219, 220,114, 2, + 255, 234,237, 1}; + +// Gradient palette "bhw2_07_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_07.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 24 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw2_07_gp ) { + 0, 92, 1, 1, + 26, 153, 20, 5, + 79, 232, 72, 12, + 127, 220,231, 89, + 173, 232, 72, 12, + 255, 92, 1, 1}; + +// Gradient palette "bhw3_32_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw3/tn/bhw3_32.png.index.html +// converted for FastLED with gammas (2.6, 2.2, 2.5) +// Size: 52 bytes of program space. + +DEFINE_GRADIENT_PALETTE( bhw3_32_gp ) { + 0, 234,231, 1, + 15, 171, 43, 6, + 40, 121, 0, 0, + 53, 95, 1, 29, + 71, 73, 1,168, + 94, 38, 63,221, + 109, 115, 51,221, + 127, 38, 63,221, + 147, 73, 1,168, + 181, 203, 28, 1, + 193, 155, 16, 11, + 216, 73, 1,168, + 255, 1, 4, 29}; + + +// Single array of defined cpt-city color palettes. +// This will let us programmatically choose one based on +// a number, rather than having to activate each explicitly +// by name every time. +// Since it is const, this array could also be moved +// into PROGMEM to save SRAM, but for simplicity of illustration +// we'll keep it in a regular SRAM array. +// +// This list of color palettes acts as a "playlist"; you can +// add or delete, or re-arrange as you wish. +const TProgmemRGBGradientPalettePtr gGradientPalettes[] = { + bhw3_32_gp, + bhw1_01_gp, + bhw1_07_gp, + bhw1_sunset3_gp, + bhw1_sunset2_gp, + bhw2_sherbet2_gp, + bhw2_39_gp, + bhw2_sunsetx_gp, + bhw2_xc_gp, + bhw2_07_gp, + }; + + +// Count of how many cpt-city gradients are defined: +const uint8_t gGradientPaletteCount = + sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr ); + void loop() +{ + EVERY_N_SECONDS( SECONDS_PER_PALETTE ) { + gCurrentPaletteNumber = addmod8( gCurrentPaletteNumber, 1, gGradientPaletteCount); + gTargetPalette = gGradientPalettes[ gCurrentPaletteNumber ]; + } + + EVERY_N_MILLISECONDS(1500) { + nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 16); + } + + colorwaves( leds, NUM_LEDS, gCurrentPalette); + + FastLED.show(); + //FastLED.delay(50); +} From 1f6540c912b2b257a0b4b19fc175d93537da7bd5 Mon Sep 17 00:00:00 2001 From: firepixie Date: Wed, 29 May 2024 12:36:10 -0700 Subject: [PATCH 2/2] Update designer_palettes_sunset.ino added SPDX info per Anne --- .../designer_palettes_sunset.ino | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino b/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino index 5bc2c3b98..805ae6afa 100644 --- a/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino +++ b/Programmable_12v_Outdoor_Cafe_Lights/designer_palettes_sunset.ino @@ -1,17 +1,19 @@ - -#include "FastLED.h" - -// ColorWavesWithPalettes +// SPDX-FileCopyrightText: 2024 Erin St Blaine for Adafruit Industries +// +// SPDX-License-Identifier: MIT +// +// Based on ColorWavesWithPalettes // Animated shifting color waves, with several cross-fading color palettes. // by Mark Kriegsman, August 2015 // +// // Color palettes courtesy of cpt-city and its contributors: // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ // // Color palettes converted for FastLED using "PaletteKnife" v1: // http://fastled.io/tools/paletteknife/ // - +#include "FastLED.h" #define DATA_PIN SCL #define LED_TYPE WS2812