Skip to content

Instantly share code, notes, and snippets.

@Tejkaran
Created April 7, 2017 17:41
Show Gist options
  • Save Tejkaran/de6fecdb33c29c967da8e87ce154c193 to your computer and use it in GitHub Desktop.
Save Tejkaran/de6fecdb33c29c967da8e87ce154c193 to your computer and use it in GitHub Desktop.
color palette understanding
#include "FastLED.h"
#define NumPixels 51 // number of LEDs in strip - count starts at 0, not 1
#define DataRate_Mhz 4 // how fast data refreshes at - [----CHECK THIS----] - slower rates are more successful when timing is not essential!!!!!
#define DataPin 11 // data pin
#define ClockPin 13 // clock Pin
CRGB leds[NumPixels];
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette; // don't know what this does
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; // don't know what this does
void setup()
{
delay(1000); // saftey first
FastLED.addLeds<APA102,DataPin,ClockPin,BGR,DATA_RATE_MHZ(DataRate_Mhz)>(leds,NumPixels);
fill_solid(leds, NumPixels, CRGB(0,0,0)); // fill all black
FastLED.show(); // show
Serial.begin(115200); // monitor speed
pinMode(7, OUTPUT); // if using the prop shield this is required
digitalWrite(7, HIGH); // if using the prop shield this is required
currentPalette = CloudColors_p; // this is a pre made color palette
currentBlending = LINEARBLEND; // options are LINEARBLEND or NOBLEND - linera is 'cleaner'
}
void loop()
{
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */ //seems to get it 'moving'
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(25);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 10;
for( int i = 0; i < NumPixels; i++)
{
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment