Palette kullanımı – ColorFromPalette

nblendPaletteTowardPalette ve ColorFromPalette ‘ın kullanımını öğrenmeye çalışıyorum.

The basic idea is that you always have a “current palette” that you’re
pulling colors from with ColorFromPalette, and you have a “target palette
which is the ‘next’ palette that you want to get to.

After that, implementation is relatively simple: just periodically call
nblendPaletteTowardPalette( currentPalette, targetPalette);

If the current palette is not yet equal to the target palette, this
function will make a few small changes to the current palette to make
it slightly more like the target. Over time, the current palette will
come to be equal to the target.

There’s no need to test the current and target for equality; it’s safe
to keep calling nblendPaletteTowardPalette even after current reaches target.
For faster blending, call nblendPaletteTowardPalette twice per loop.

Kod

uint8_t maxChanges = 24;
nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);

static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;

for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex + sin8(i*16), brightness);
colorIndex += 3;
}
}

 

Kendi paletlerimi yaratmak için:

#include <FastLED.h>
#include <pixeltypes.h>

#define LED_PIN 2
#define NUM_LEDS 300
#define BRIGHTNESS 96
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

CRGBPalette16 currentPalette( CRGB::Black);
CRGBPalette16 targetPalette;

extern const TProgmemRGBPalette16 myPalette PROGMEM;

void setup() {

targetPalette = myPalette;

delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}

void loop()
{
targetPalette = myPalette;
uint8_t maxChanges = 24;
nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);

static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
// FillLEDsFromPaletteColors( startIndex);
FillLEDsFromPaletteColors( 300);

FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);

} //END_LOOP

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;

for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex + sin8(i * 16), brightness);
colorIndex += 3;
}
}

const TProgmemPalette16 myPalette PROGMEM =
{
CRGB::BlueViolet,
CRGB::DarkMagenta,
CRGB::DarkOrchid,
CRGB::DarkSlateBlue,

CRGB::DarkViolet,
CRGB::Fuchsia,
CRGB::Indigo,
CRGB::Magenta,

CRGB::MediumOrchid,
CRGB::MediumPurple,
CRGB::Violet,
CRGB::MediumVioletRed,

CRGB::Orchid,
CRGB::Plum,
CRGB::Purple,
CRGB::Thistle,
};

 

ColorFromPalette( currentPalette, colorIndex + sin8(i * 16), brightness)

leds[i] = ColorFromPalette( currentPalette, colorIndex + sin8(i * 16), brightness, blending);

 

currentPalette:

for ( int i = 0; i < NUM_LEDS; i++) {

void FillLEDsFromPaletteColors( uint8_t colorIndex) : c

leds[i] = ColorFromPalette( currentPalette, i, brightness,NOBLEND);

 

ColorIndex: Paletteki her rengin sırası ile alakalı. 16 renk toplam 256 girdiye özetleniyor.

Index 0 : 1. Renk
Index 16 : 2. Renk
Index 32 : 3. Renk
Index 48  : 4. Renk
Index 64 : 5. Renk
Index 80 : 6. Renk
Index 96 : 7. Renk
Index 112 : 8. Renk
Index 128 : 9. Renk
Index 144 : 10. Renk
Index 160: 11. Renk
Index 176: 12. Renk
Index 192: 13. Renk
Index 208: 14. Renk
Index 224: 15. Renk
Index 240: 16. Renk

Brightness:

blending: NOBLEND, LINEARBLEND

for ( int i = 0; i < NUM_LEDS; i++) {

leds[i] = ColorFromPalette( currentPalette, i, brightness,NOBLEND);

 

Her renkten 16şar adet şerit sonuna kadar gösteriliyor. Renkler arası Geçişler sert.

leds[i] = ColorFromPalette( currentPalette, i, brightness,LINEARBLEND);

 

Her renkten 16şar adet şerit sonuna kadar gösteriliyor. Renkler arası Geçişler yumuşak.

Leave a Reply