Guest User

flex_radiate for ikea lamp

a guest
Nov 17th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. //declare this somewhere else, just here as a reminder
  2. //float divFactor;
  3.  
  4.  
  5. void flex_radiate() {
  6.  
  7.   readMSGEQ7_mono(); // or ReadAudio(), whatever you want to call it
  8.  
  9.   ledindex = HALF_POS;
  10.   k = 0;
  11.  
  12.   for (int band = 0; band < 7; band++) {
  13.  
  14.     k = (band + 1) % 7; // doesn't work perfectly, but serves as a value for the NEXT band number
  15.     half_MAPPED_AMPLITUDE = half_mapped[band];
  16.     // there is a lot of math here that helps smooth brightness values
  17.     // at the EDGES of each band on the led strip, so it doesn't immediately go from one color to another
  18.     // this helps a TON for having it wrapped around a tube
  19.     divFactor = 1.0f / half_MAPPED_AMPLITUDE;
  20.  
  21.     // segment is a variable (declare it somewhere) for FINAL led number of each band, with ledindex
  22.     // indicating the START of each band. it is incremented after each cycle
  23.     segment = half_MAPPED_AMPLITUDE + ledindex;
  24.     hue = band * 35; // or whatever you want. just determines how much of the hue spectrum fits on the strip
  25.     //hue += mono[0] * 0.01;
  26.  
  27.     for (index = ledindex; index < segment; index++) {
  28.       brightness = (mono[band] * (half_MAPPED_AMPLITUDE - cnt) * divFactor) + (mono[k] * cnt * divFactor);
  29.       //brightness = map(brightness, 0, 255, 100, 255);
  30.       leds[index] = CHSV(hue, saturation, brightness);
  31.       // to mirror to the bottom half of the strip
  32.       leds[HALF_POS - (index - HALF_POS)] = CHSV(hue, saturation, brightness);
  33.       cnt++;
  34.     }
  35.     cnt = 0;
  36.     ledindex += half_MAPPED_AMPLITUDE;
  37.   }
  38.   // ehhh, blur it. why not.
  39.   blur2d(leds, kMatrixWidth, kMatrixHeight, 100);
  40.   FastLED.show();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment