Browse Source

add methods for audio and leds pa

sound fadeout and stop methods
leds BEAT palette
untested, compiles
Etienne Landon 8 years ago
parent
commit
ae14313a5a
3 changed files with 45 additions and 24 deletions
  1. 4 5
      DownTigerDown.ino
  2. 28 19
      SDcard.ino
  3. 13 0
      fastLed.ino

+ 4 - 5
DownTigerDown.ino

@@ -55,6 +55,8 @@ FadeLed dimmer(DIMMER_PIN);
 byte dimmer_low = 20;
 byte dimmer_mid = 60;
 byte dimmer_high = 80;
+bool dimmer_random ; // activate short-circuit effect
+int dimmer_move = 10 ; // organic variation around base value
 
 // FastLED
 #define NUM_LEDS_LUSTRE 240
@@ -78,7 +80,8 @@ CRGBPalette16 palette_MER (CRGB::DarkBlue);
 CRGBPalette16 palette_SOLEIL (CRGB::Orange);;
 CRGBPalette16 palette_CREPUSCULE (CRGB::YellowGreen);
 CRGBPalette16 palette_FLAMINGO (CRGB::LightCoral);
-
+bool palette_BEAT ; // activate beat sync palette
+int paletteBeatStart ; //to resync effect on activation
 
 //Functions prototypes
 void EvtResetButtonContext ();
@@ -167,8 +170,4 @@ void setup() {
 
 USE_EVENTUALLY_LOOP(mgr) // Use this instead of your loop() function.
 
-//void loop() {
-//  mgr.loopIteration();
-//  //updateAll();
-//}
 

+ 28 - 19
SDcard.ino

@@ -73,8 +73,17 @@ bool readSDFile() {
       if (selector == "sound") {
         String track = getSubstring(buf, ' ', 2) ;
         String out = getSubstring(buf, ' ', 1) ;
-        Serial.println("Playing track " + track + " to output " + out);
-        tsunami.trackPlayPoly(track.toInt(), out.toInt()-1, true);     
+        if (out == "stop") { tsunami.stopAllTracks(); Serial.println("Stopping all sounds");}
+        if (out == "fadeout") {
+          Serial.println("Fading all sounds") ;
+          for (int track ; track < 60 ; track++) {
+            tsunami.trackFade(track, 0, 500, 1) ;            
+          }
+        }
+        else {
+          Serial.println("Playing track " + track + " to output " + out);
+          tsunami.trackPlayPoly(track.toInt(), out.toInt()-1, true);     
+        }
       }
       
       else if (selector == "led") {
@@ -85,6 +94,8 @@ bool readSDFile() {
         String fadeTime = getSubstring(buf, ' ', 4);
         Serial.println(getSubstring(buf, ' ', 2));
         if (zone == "lustre"){ 
+          if (palette == "BEAT"){palette_BEAT = true; paletteBeatStart = millis();}
+          else { palette_BEAT = false ;}
           if (palette == "MER"){lustre_targetPalette = palette_MER ;}
           else if (palette == "SOLEIL"){lustre_targetPalette = palette_SOLEIL ;}
           else if (palette == "CREPUSCULE"){lustre_targetPalette = palette_CREPUSCULE ;}
@@ -92,6 +103,17 @@ bool readSDFile() {
           lustre_targetBrightness = bright.toInt();
           lustre_stepBrightness = constrain( abs((lustre_targetBrightness - lustre_currentBrightness)) / (float)(fadeTime.toInt()/refreshRate), 1, 255) ;
           if(lustre_currentBrightness > lustre_targetBrightness) { lustre_stepBrightness *= -1 ;}
+          
+        }
+        else if (zone == "table"){ 
+          if (palette == "MER"){table_targetPalette = palette_MER ;}
+          else if (palette == "SOLEIL"){table_targetPalette = palette_SOLEIL ;}
+          else if (palette == "CREPUSCULE"){table_targetPalette = palette_CREPUSCULE ;}
+          else if (palette == "FLAMINGO"){table_targetPalette = palette_FLAMINGO ;}
+          table_targetBrightness = bright.toInt();
+          table_stepBrightness = constrain( abs((table_targetBrightness - table_currentBrightness)) / (float)(fadeTime.toInt()/refreshRate), 1, 255) ;
+          if(table_currentBrightness > table_targetBrightness) { table_stepBrightness *= -1 ;}
+        }
           Serial.print ("LEDS : zone ");
           Serial.print (zone);
           Serial.print (" - palette ");
@@ -102,29 +124,16 @@ bool readSDFile() {
           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 (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));
       }
+
+
      
       else if (selector == "dimmer") {
         String dim_val = getSubstring(buf, ' ', 1);
+        
         int dimmer_value;
         int dimmer_fade = getSubstring(buf, ' ', 2).toInt();
         Serial.println("Dimmer fade à " + dim_val + " en " + dimmer_fade + "ms");

+ 13 - 0
fastLed.ino

@@ -1,5 +1,11 @@
 
 ///////////////////////// FastLED ///////////////////////////////////////
+void beatSyncPalette() {
+  
+  uint8_t speed = beatsin8(6,0,255);
+  CRGB color = blend(CRGB::Aqua, CRGB::Orange, speed);
+  fill_solid(lustre_currentPalette, 16, color);
+}
 
 
 void FillLEDsFromPaletteColors( CRGB leds[], int NUM_LED, CRGBPalette16 palette, uint8_t colorIndex){
@@ -20,12 +26,17 @@ float FadingBrightness (int FastLEDindex, float currentBrightness, float targetB
 }
 
 void updateLeds(){
+  
   nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
   nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
   nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
   nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
   nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
   nblendPaletteTowardPalette(lustre_currentPalette, lustre_targetPalette, 48);
+
+  if(palette_BEAT) {
+    beatSyncPalette();
+  }
   FillLEDsFromPaletteColors(lustreLeds,NUM_LEDS_LUSTRE, lustre_currentPalette, 0);
 //  uint8_t secondHand = (millis() / 10) ;
   lustre_currentBrightness = FadingBrightness( 0, lustre_currentBrightness, lustre_targetBrightness ,lustre_stepBrightness);
@@ -40,3 +51,5 @@ byte percent2PWM ( byte valueIn ) {
   return map (valueIn, 0, 100, 14, 92);
 }
 
+
+