Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chemdoc77/681be894dabbe3a5f5b0c9d795db1423 to your computer and use it in GitHub Desktop.
Save chemdoc77/681be894dabbe3a5f5b0c9d795db1423 to your computer and use it in GitHub Desktop.
CD77 Special Request for Changing Colors After a Long Period_of Time
/* This sketch by Chemdoc77 is a special request for changing colors after a long period of time.
It is based on Mark Kriegsman's PaletteCrossfade.ino and his PerformanceTime code at;
https://gist.github.com/kriegsman/1f7ccbbfa492a73c015e
and
https://gist.github.com/kriegsman/a916be18d32ec675fea8
*/
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 64
#define BRIGHTNESS 60
#define LED_TYPE NEOPIXEL
CRGB leds[NUM_LEDS];
//==== Predeclared palettes ==========
// Gradient palette "ib_jul01_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 16 bytes of program space.
DEFINE_GRADIENT_PALETTE( ib_jul01_gp ) {
0, 194, 1, 1,
94, 1, 29, 18,
132, 57,131, 28,
255, 113, 1, 1};
// Gradient palette "es_vintage_57_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_57.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_vintage_57_gp ) {
0, 2, 1, 1,
53, 18, 1, 0,
104, 69, 29, 1,
153, 167,135, 10,
255, 46, 56, 4};
CRGBPalette16 mypal= es_vintage_57_gp; // look palette to change
//===== Time Performance code =======
uint32_t gTimeCodeBase = 0;
uint32_t gTimeCode = 0;
uint32_t gLastTimeCodeDoneAt = 0;
uint32_t gLastTimeCodeDoneFrom = 0;
#define TC(HOURS,MINUTES,SECONDS) \
((uint32_t)(((uint32_t)((HOURS)*(uint32_t)(3600000))) + \
((uint32_t)((MINUTES)*(uint32_t)(60000))) + \
((uint32_t)((SECONDS)*(uint32_t)(1000)))))
#define AT(HOURS,MINUTES,SECONDS) if( atTC(TC(HOURS,MINUTES,SECONDS)) )
#define FROM(HOURS,MINUTES,SECONDS) if( fromTC(TC(HOURS,MINUTES,SECONDS)) )
static bool atTC( uint32_t tc)
{
bool maybe = false;
if( gTimeCode >= tc) {
if( gLastTimeCodeDoneAt < tc) {
maybe = true;
gLastTimeCodeDoneAt = tc;
}
}
return maybe;
}
static bool fromTC( uint32_t tc)
{
bool maybe = false;
if( gTimeCode >= tc) {
if( gLastTimeCodeDoneFrom <= tc) {
maybe = true;
gLastTimeCodeDoneFrom = tc;
}
}
return maybe;
}
void RestartPerformance()
{
gLastTimeCodeDoneAt = 0;
gLastTimeCodeDoneFrom = 0;
gTimeCodeBase = millis();
}
//======Key part of the time code ========
void Performance()
{
FROM(0,0,00.000) { fill_solid( leds, NUM_LEDS, CRGB::Red); FastLED.show();}
FROM(0,0,08.000) { fill_solid( leds, NUM_LEDS, CRGB::Blue); FastLED.show();}
FROM(0,0,16.000) {fill_solid( leds, NUM_LEDS, CRGB::Green); FastLED.show();}
FROM(0,0,24.000) {fill_solid( leds, NUM_LEDS, CRGB::Purple); FastLED.show();}
// FROM(0,0,18.000) {fill_gradient_RGB (leds, NUM_LEDS, CHSV(180,255,255), CHSV(200,255,255), FORWARD_HUES);FastLED.show();} // purple range
FROM(0,0,32.000) {fill_gradient_RGB (leds, NUM_LEDS, CRGB::Blue, CRGB::Purple);FastLED.show();}
FROM(0,0,40.000) {static uint8_t startIndex = 0; startIndex = startIndex + 1; mypal= CRGBPalette16( CRGB::Blue, CRGB::Blue, CRGB::Red, CRGB::Red); FillLEDsFromPaletteColors( startIndex , mypal); FastLED.delay(20);}
FROM(0,0,52.000) {static uint8_t startIndex = 0; startIndex = startIndex + 1; mypal=es_vintage_57_gp; FillLEDsFromPaletteColors( startIndex , mypal); FastLED.delay(20);}
AT(0,1,04.000) {RestartPerformance(); }
}
//===== SETUP ========
void setup() {
delay(1000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
FastLED.setMaxPowerInVoltsAndMilliamps(5,1000);
set_max_power_indicator_LED(13);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
//Time Performance code
RestartPerformance();
}
//=====LOOP============
void loop()
{
//Time Performance code
gTimeCode = millis() - gTimeCodeBase;
Performance();
}
//======== Function(s) ============
void FillLEDsFromPaletteColors( uint8_t colorIndex, CRGBPalette16& pal_x)
{
uint8_t brightness =255;
CRGB color=ColorFromPalette( pal_x, colorIndex, brightness, LINEARBLEND);
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = color;
colorIndex += 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment