Browse Source

Leds control from SD file

control is working, fade is not : does not meet the condition =
targetBrightness
try looking direction and using < > ?
Etienne Landon 8 years ago
parent
commit
b54e409a06
4 changed files with 41 additions and 15 deletions
  1. 5 3
      DownTigerDown.ino
  2. 28 7
      SDcard.ino
  3. 4 2
      eventually.ino
  4. 4 3
      fastLed.ino

+ 5 - 3
DownTigerDown.ino

@@ -47,6 +47,8 @@ unsigned long delay_length ;
 bool inibSDreading = true;
 bool delay_flag ; //prevent first event to fire
 
+byte refreshRate = 25 ;
+
 //Dimmer
 #define DIMMER_PIN 9
 FadeLed dimmer(DIMMER_PIN);
@@ -57,9 +59,9 @@ byte dimmer_high = 80;
 // FastLED
 #define NUM_LEDS_LUSTRE 240
 CRGB lustreLeds[NUM_LEDS_LUSTRE];
-byte lustre_currentBrightness ;     //for fading
-byte lustre_targetBrightness ;
-int lustre_stepBrightness;
+float lustre_currentBrightness ;     //for fading
+float lustre_targetBrightness = 255 ;
+float lustre_stepBrightness;
 CRGBPalette16 lustre_currentPalette( CRGB::Blue);
 CRGBPalette16 lustre_targetPalette( CRGB::Red );
 

+ 28 - 7
SDcard.ino

@@ -78,25 +78,46 @@ bool readSDFile() {
       }
       
       else if (selector == "led") {
-        Serial.println("led");
-//        String mode = getSubstring(buf, ' ', 1);
-//        if (mode == "L"){ 
+        //Serial.println("led");
+        String zone = getSubstring(buf, ' ', 1);
+        String palette = getSubstring(buf, ' ', 2);
+        String bright = getSubstring(buf, ' ', 3);
+        String fadeTime = getSubstring(buf, ' ', 4);
+        
+        if (zone == "lustre"){ 
+          if (palette = "MER"){lustre_targetPalette = palette_MER ;}
+          else if (palette = "SOLEIL"){lustre_targetPalette = palette_SOLEIL ;}
+          else if (palette = "CREPUSCULE"){lustre_targetPalette = palette_CREPUSCULE ;}
+          else if (palette = "FLAMINGO"){lustre_targetPalette = palette_FLAMINGO ;}
+          lustre_targetBrightness = bright.toInt();
+          lustre_stepBrightness = 10 * (lustre_targetBrightness - lustre_currentBrightness) / (float)(fadeTime.toInt()/refreshRate) ;
+          Serial.print ("LEDS : palette ");
+          Serial.print (palette);
+          Serial.print (" - brightness : ");
+          Serial.print (lustre_targetBrightness);
+          Serial.print (" - fade time : ");
+          Serial.print (fadeTime);
+          Serial.print (" - steps : ");
+          Serial.println (lustre_stepBrightness);
+        }
+          
+//          if(
 //          int R = getSubstring(buf, ' ', 2).toInt();
 //          int G = getSubstring(buf, ' ', 3).toInt();
 //          int B = getSubstring(buf, ' ', 4).toInt();
 //          for (int i ; i<NUM_LEDS_LUSTRE ; i++) {
 //            lustreLeds[i].setRGB(R, G, B) ;
 //          }         
-//        }
-//        if (mode == "T"){ 
+        
+        if (zone == "table"){ 
 //          int R = getSubstring(buf, ' ', 2).toInt();
 //          int G = getSubstring(buf, ' ', 3).toInt();
 //          int B = getSubstring(buf, ' ', 4).toInt();
 //          for (int i ; i<NUM_LEDS_TABLE ; i++) {
 //            tableLeds[i].setRGB(R, G, B) ;
 //          }         
-//        }
-//        Serial.println("Led mode " + getSubstring(buf, ' ', 1));
+        }
+        //Serial.println("Led mode " + getSubstring(buf, ' ', 1));
       }
      
       else if (selector == "dimmer") {

+ 4 - 2
eventually.ino

@@ -24,8 +24,10 @@ bool updateAll() {
   //tsunami.update();
   updateLeds() ;
 //  FastLED.show();
+  
   return false;
   
+  
 }
 
 
@@ -107,7 +109,7 @@ void stopAll() {
 bool button0(){
   buttonFocus(0) ;
   //lustre_targetPalette = palette_FLAMINGO ;
-  //lustre_currentBrightness = 0;
+  //lustre_currentBrightness = 255;
   return false;
 }
 bool button1(){
@@ -178,7 +180,7 @@ void EvtResetButtonContext () {
 
   inibSDreading = true ;
   mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
-  mgr.addListener(new EvtTimeListener(50, true, (EvtAction)updateAll));
+  mgr.addListener(new EvtTimeListener(refreshRate, true, (EvtAction)updateAll));
   //mgr.addListener(new EvtTimeListener(40, true, (EvtAction)fastLeds));
   Serial.println("Done resetting ");
   

+ 4 - 3
fastLed.ino

@@ -10,10 +10,11 @@ void FillLEDsFromPaletteColors( CRGB leds[], int NUM_LED, CRGBPalette16 palette,
   }
 }
 
-byte FadingBrightness (int FastLEDindex, byte currentBrightness, byte targetBrightness, int step) {
+float FadingBrightness (int FastLEDindex, float currentBrightness, float targetBrightness, int step) {
   if (currentBrightness != targetBrightness) { currentBrightness += step ;}
   //else Serial.println("fade done");
-  FastLED[FastLEDindex].showLeds(currentBrightness) ;
+  Serial.println(currentBrightness);
+  FastLED[FastLEDindex].showLeds((int)currentBrightness) ;
   return currentBrightness ;
 }
 
@@ -26,7 +27,7 @@ void updateLeds(){
   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);
+  lustre_currentBrightness = FadingBrightness( 0, lustre_currentBrightness, lustre_targetBrightness ,lustre_stepBrightness);
 }