Skip to content

Instantly share code, notes, and snippets.

@Tejkaran
Created April 25, 2017 10:11
Show Gist options
  • Save Tejkaran/76c380049991f29dfecb76a1af2f30e3 to your computer and use it in GitHub Desktop.
Save Tejkaran/76c380049991f29dfecb76a1af2f30e3 to your computer and use it in GitHub Desktop.
Color Palette
#include "FastLED.h"
#define NumPixels 51 // number of LEDs in strip - count starts at 0, not 1
#define DataRate_Mhz 12 // 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];
uint8_t i;
uint8_t startPoint = 0;
uint8_t brightness = 10;
TBlendType blendingType; //tBlendType is a data type like int/char/uint8_t etc., used to choose LINERBLEND and NOBLEND
DEFINE_GRADIENT_PALETTE(tejkaranPalette ){ // this one works
0, 0, 0, 0, //
16, 255, 0, 0, // red
32, 0, 0, 0, //
48, 255, 128, 0, // orange
64, 0, 0, 0, //
80, 255, 255, 0, // yellow
96, 0, 0, 0, //
112, 0, 255, 0, // green
128, 0, 0, 0, //
144, 0, 128, 255, // cyan
160, 0, 0, 0, //
176, 0, 0, 255, // blue
192, 0, 0, 0, //
208, 255, 0, 255, // indigo
224, 0, 0, 0, //
250, 255, 0, 127, // violet
255, 0, 0, 0, //
}; //
DEFINE_GRADIENT_PALETTE(tejkaranPaletteTwo ){
0, 0, 0, 0, //
10, 255, 0, 0, // red
20, 0, 0, 0, //
30, 255, 128, 0, // orange
40, 0, 0, 0, //
50, 255, 255, 0, // yellow
60, 0, 0, 0, //
70, 128, 255, 0, // light green
80, 0, 0, 0, //
90, 0, 255, 0, // green
100, 0, 0, 0, //
110, 0, 255, 128, // turquoise
120, 0, 0, 0, //
130, 0, 255, 255, // cyan
140, 0, 0, 0, //
150, 0, 128, 255, // light blue
160, 0, 0, 0, //
170, 0, 0, 255, // blue
180, 0, 0, 0, //
190, 127, 0, 255, // purple
200, 0, 0, 0, //
210, 255, 0, 255, // pink
220, 0, 0, 0, //
230, 255, 0, 127, // indigo
240, 0, 0, 0, //
250, 128, 128, 128, // grey
255, 0, 0, 0, }; //
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ocal/tn/spectrums-rainbow-002.png.index.html
DEFINE_GRADIENT_PALETTE( spectrums_rainbow_002_gp ) {
12, 255, 0, 0,
38, 255, 97, 0,
63, 255,255, 0,
89, 0,255, 0,
114, 0, 55, 0,
140, 0,255,255,
165, 0, 0,255,
191, 10, 0, 47,
216, 213, 57,214,
242, 255, 0, 0,};
// not sure why but this Rainbow does not work
CRGBPalette16 currentPalette(tejkaranPalette);
void setup()
{
delay(2000); // saftey first
FastLED.addLeds<APA102,DataPin,ClockPin,BGR,DATA_RATE_MHZ(DataRate_Mhz)>(leds,NumPixels); //.setCorrection(CRGB( 255, 255, 240));
fill_solid(leds, NumPixels, CRGB(0,0,0)); // fill all black
FastLED.show(); // show
Serial.begin(115200); // monitor speed
blendingType = NOBLEND; // options are LINEARBLEND or NOBLEND - linear is 'cleaner'
}
void loop()
{
// startPoint says where in the strip you want to start. This info is then passed to the fillStrip function
// which then uses 'startPoint' int as the start point. +=4(or whatever number) every go to get it moving,
// but it will start at 'startPoint' every time. This increases by 1 to get it moving.
// There are two moving parts. The beginning position(startPoint) and the in motion move (paletteMovement)
startPoint = startPoint + 1; //set as 0 to see the palette gradient change; +1 to get it moving
fillStrip(startPoint);
FastLED.show();
FastLED.delay(1000/NumPixels);
}
// The function ,fillStrip, goes through for all the leds, starting at the startPoint == paletteMovement
void fillStrip(uint8_t paletteMovement) //make the variable paletteMovement here because then it can be changed to be startPoint at the beginnign every time
{
for(int i = 0; i < NumPixels; i++)
{
leds[i] = ColorFromPalette(currentPalette, paletteMovement, brightness, blendingType);
paletteMovement += 4 ; //value between 0 and 10, how much of the lights should be lit up at once, 0 being all
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment