Переглянути джерело

fading and palette blending

Etienne Landon 8 роки тому
батько
коміт
a811c39483
1 змінених файлів з 30 додано та 10 видалено
  1. 30 10
      DownTigerDown/DownTigerDown.ino

+ 30 - 10
DownTigerDown/DownTigerDown.ino

@@ -58,8 +58,8 @@ CRGB lustreLeds[NUM_LEDS_LUSTRE];
 byte lustre_currentBrightness ;     //for fading
 byte lustre_targetBrightness ;
 int lustre_stepBrightness;
-CRGBPalette16 lustre_currentPalette( CRGB::Pink);
-CRGBPalette16 lustre_targetPalette( CRGB::Blue );
+CRGBPalette16 lustre_currentPalette( CRGB::Blue);
+CRGBPalette16 lustre_targetPalette( CRGB::Red );
 
 #define NUM_LEDS_TABLE 50
 CRGB tableLeds[NUM_LEDS_TABLE];
@@ -69,6 +69,13 @@ int table_stepBrightness;
 CRGBPalette16 table_currentPalette( CRGB::Pink);
 CRGBPalette16 table_targetPalette( CRGB::Blue );
 
+// FastLED Palettes
+CRGBPalette16 TIGER_DOWN_MER (CRGB::DarkBlue);
+CRGBPalette16 SOLEIL (CRGB::Orange);
+CRGBPalette16 CREPUSCULE (CRGB::YellowGreen);
+CRGBPalette16 FLAMINGO (CRGB::LightCoral);
+
+
 //Functions prototypes
 void EvtResetButtonContext ();
 void tlcWrite();
@@ -236,22 +243,26 @@ void testAll(){
 ///////////////////////// FastLED ///////////////////////////////////////
 
 
-void FillLEDsFromPaletteColors( uint8_t colorIndex){
+void FillLEDsFromPaletteColors( CRGB leds[], int NUM_LED, CRGBPalette16 palette, uint8_t colorIndex){
   uint8_t brightness = 255;
-  for( int i = 0; i < NUM_LEDS_LUSTRE; i++) {
-    lustreLeds[i] = ColorFromPalette( lustre_currentPalette, colorIndex + sin8(i*16), 255);
+  for( int i = 0; i < NUM_LED; i++) {
+    leds[i] = ColorFromPalette( palette, colorIndex + sin8(i*16), 255);
     colorIndex += 3;
   }
 }
 
-void FadingBrightness (int FastLEDindex, byte currentBrightness, byte targetBrightness, int step) {
+byte FadingBrightness (int FastLEDindex, byte currentBrightness, byte targetBrightness, int step) {
+  if (currentBrightness != targetBrightness) { currentBrightness += step ;}
+  else Serial.println("fade done");
   FastLED[FastLEDindex].showLeds(currentBrightness) ;
+  return currentBrightness ;
 }
 
 void updateLeds(){
-  FillLEDsFromPaletteColors( 0);
-  uint8_t secondHand = (millis() / 100) % 60;
-  FadingBrightness( 0, secondHand*10,100,5);
+  nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
+  FillLEDsFromPaletteColors(lustreLeds,NUM_LEDS_LUSTRE, lustre_currentPalette, 0);
+//  uint8_t secondHand = (millis() / 10) ;
+  lustre_currentBrightness = FadingBrightness( 0, lustre_currentBrightness ,255,1);
 }
 
 
@@ -461,19 +472,28 @@ void stopAll() {
 
 bool button0(){
   buttonFocus(0) ;
+  lustre_targetPalette = FLAMINGO ;
+  lustre_currentBrightness = 0;
   return false;
 }
 bool button1(){
   buttonFocus(1) ;
+  lustre_targetPalette = SOLEIL;
+  lustre_currentBrightness = 0;
 //  testAll(); 
   return false;
 }
 bool button2(){
   buttonFocus(2) ;
+  lustre_targetPalette = CREPUSCULE ;
+  lustre_currentBrightness = 0;
+  
   return false;
 }
 bool button3(){
   buttonFocus(3) ;
+  lustre_targetPalette =TIGER_DOWN_MER;
+  lustre_currentBrightness = 0;
   return false;
 }
 bool button4(){
@@ -521,7 +541,7 @@ void EvtResetButtonContext () {
 //  pSD = new EvtTimeListener(5, true, (EvtAction)readSDFile);  
   inibSDreading = true ;
   mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
-  mgr.addListener(new EvtTimeListener(50, true, (EvtAction)updateAll));
+  mgr.addListener(new EvtTimeListener(25, true, (EvtAction)updateAll));
   //mgr.addListener(new EvtTimeListener(40, true, (EvtAction)fastLeds));
   
 }