Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Interactive LED strip feat: MSGEQ7, FastSPI_LED, IRRemote

By: HaDJCongdon on Sep 6th, 2012  |  syntax: C  |  size: 19.91 KB  |  views: 2,252  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2. This code is for controlling a digital LED strip using an IR remote, the strip responds
  3. to audio using the MSGEQ7 audio frequency multiplexer. The infrared remote used is from
  4. some crappy stereo remote but some tips for using an xbox remote are included and commented
  5. out.
  6.  
  7. fastSPI_LED:
  8. http://code.google.com/p/fastspi/
  9.  
  10. IR library and code based off Ken Sheriff:
  11. http://www.arcfn.com/2010/12/64-bit-rc6-codes-arduino-and-xbox.html
  12.  
  13. The fast SPI library uses an interrupt timer to do its own pushing of signals to the strip.
  14. An array with an RGB strucure is populated with values then you tell it to send that to the
  15. strip.
  16.  
  17. The problem is IR-decode also runs in the background based on interrupts, so it will return
  18. junk data for some reason unelss you comment out cli() in the fast SPI library (the .cpp
  19. file, there is an instance for each chip type). cli() is used to turn off background
  20. interrupts. I held down the remote button for a while, nothing bad happened to the strip
  21. display, guess its ok.
  22.  
  23. Special thanks to Andrew Tuline for confirming this tip, his project is pretty much
  24. the same thing as this.
  25.  
  26. -James Congdon http://hackaday.com/author/jcongdon/
  27. Project Writeup: http://hackaday.com/2012/09/11/disco-planet-a-massive-rgbw-led-array-in-a-6-globe/
  28. 9/13/12: fixed some comment typos and deleted commented notes on stuff that I had already
  29. fixed. Also moved the section divider that was out of place.  -James
  30. */
  31.  
  32. #include <FastSPI_LED.h>
  33. #include <IRremote.h>
  34.  
  35. //------------------ Definitions ---------------------
  36.  
  37. //IR Remote
  38. // XBOX: buttons that are held down send separate codes, long long used for xbox
  39. // NOTE: codes currently are for cheap POS stereo remote.
  40. //#define IRCode_UP 0x0800ff41eLL    
  41. #define IRCode_PWR 0xDCC8B2BE
  42. #define IRCode_PREV 0xD2E3379E
  43. #define IRCode_NEXT 0xF200A55A
  44. #define IRCode_STOP 0x72BECA1F
  45. #define IRCode_PLAY 0x99EE44DF
  46.  
  47. //LED Strip
  48. // Clock is set at Pin 13, Data at Pin 11, this can not be changed.
  49. #define PixelCount 240            //Set you number of LED pixels here
  50. #define PixelCountZB PixelCount-1 //zero biased values since the array's 0 position is the first pixel
  51. #define halfStrip PixelCount/2    
  52. #define halfStripZB halfStrip-1  
  53.  
  54. //MSGEQ7
  55. #define noiseLvl 100  // the eq output is 0-5v, so 0-1024, this sets a cutoff level below which noise is ignored
  56.  
  57. //functions
  58. #define billyD .15 //for the smooth function
  59.  
  60. //------------------ Pin assignments -----------------------
  61. //MSGEQ7
  62. const int analogPin = 0;        // read from multiplexer using analog input
  63. const int analogPin2 = 1;        // read random from this, maybe something else?
  64. const int strobePin = 4;        // MSGEQ7 strobe pin
  65. const int resetPin = 5;         // MSGEQ7 reset pin
  66. const int buttonPin = 8;      // Pin a button (active high) is connected to
  67. const int statusPin = 7;     //3 watt status LED, PWM not supported on this pin, bad
  68.  
  69. //IR Receiver
  70. int RECV_PIN = 6;
  71.  
  72. //LED Strip
  73. //const int fSPI_PIN = 3; //pin only used for TM1809 strip (may be missing other initializations for this strip)
  74.  
  75. //------------------ Global Variables -----------------------
  76.  
  77. //Infrared
  78. IRrecv irrecv(RECV_PIN);
  79. //int IRstate = HIGH; //dunno what this does
  80. //iIRrecv blink13(0); //pin 13 disabled since the led strip is wont to use it
  81. decode_results results;
  82.  
  83. //Function
  84. int ledRed = 0; //using these so functions can output 3 values
  85. int ledGreen = 0;
  86. int ledBlue = 0;
  87. int mode = 0;   // Mode index
  88. int buttonState = 0;
  89. int LoopCnt = 0;             // Loop Counter used in several functions, should not be less than 0 but can be large
  90. unsigned long LoopStart = 0;  // Loop Timestamp used in slowWheel
  91. boolean StrobeOn = true;      // Strobe state
  92. int irscale = 0;              //so IR remote can mess with delay times
  93.  
  94. //MSGEQ7
  95. int spectrumValue[7];     // to hold a2d values 0-1024
  96.  
  97. //LED Strip
  98. struct CRGB { unsigned char r; unsigned char g; unsigned char b; }; //sets the bit order of the LED values, so if strip is grb you just order these differently
  99. struct CRGB *leds;  //defines pointer to CRGB as *leds
  100.  
  101. //------------- SETUP ------------------------
  102. void setup() {
  103.    
  104. //------------------ Debug -----------------------
  105. //  Serial.begin(9600);
  106. //  Serial.println("Starting up...");
  107.  
  108.  //------------------ Setup IR Remote -----------------------
  109.  
  110.   irrecv.enableIRIn(); // Start the IR receiver
  111.   irrecv.blink13(false);
  112.  
  113. //------------------ Setup FastSPI -----------------------
  114.  
  115.   FastSPI_LED.setCPUPercentage(50);  // how often to update leds: start with 50% CPU usage. up this if the strand flickers or is slow
  116.  
  117.   FastSPI_LED.setLeds(PixelCount);
  118.   FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);   //other drivers supported: TM1809, LPD6803, HL1606, 595, WS2801
  119.   //FastSPI_LED.setPin(fSPI_PIN); //pin only used for TM1809
  120.   FastSPI_LED.setDataRate(3); //if random flashing occurs (ws2801s i'm looking at you) set to 1-7 to slow data rate
  121.   FastSPI_LED.init();
  122.   FastSPI_LED.start();
  123.  
  124.   leds = (struct CRGB*)FastSPI_LED.getRGBData(); //magical array of LED, idk what this line does but it's required
  125.  
  126.   // Update the strip to clear wonkily powerup drivers
  127.   memset(leds, 0, PixelCount * 3); //memset blanks without writing
  128.   FastSPI_LED.show();              //but we write next anyway, oh well.
  129.  
  130.   //------------------ Setup MSGEQ7 -----------------------
  131.   pinMode(buttonPin, INPUT);
  132.   pinMode(analogPin, INPUT);
  133.   pinMode(strobePin, OUTPUT);
  134.   pinMode(resetPin, OUTPUT);
  135.   digitalWrite(resetPin, LOW);
  136.   digitalWrite(strobePin, HIGH);
  137.   digitalWrite(statusPin, HIGH);
  138.  
  139.   //------------------ Other Setup -----------------------
  140.   analogReference(DEFAULT); //change to default to use 1v, though this is fine (eq is 0-5 though)
  141. //pinMode(analogPin2, INPUT); //use this for random
  142.  
  143. }
  144.  
  145. void loop() {
  146.  
  147.   //------------------ Check Button -----------------------
  148.   checkButton(300);
  149.   // Serial.println(buttonState);
  150.  
  151.   //------------------ Check IR Remote ----------------------
  152.   checkIR();
  153.  
  154.   // ------------------ Execute the current effect based on value of mode ----------------------
  155.  
  156.   //Serial.println(mode, DEC);
  157.  
  158.   switch (mode) {
  159.     case 0:
  160.         EQcolorOrgan();
  161.         delay(20);
  162.         break;
  163.  
  164.     case 1:
  165.         EQcenterBar();
  166.         delay(15);
  167.         break;        
  168.        
  169.     case 2:
  170.         SlowWheel(100 + (irscale * 10)); //SLOW wheel
  171.         break;
  172.  
  173.     case 3:
  174.         FullFollow();
  175.         delay(5 + irscale);
  176.         break;        
  177.        
  178.     case 4:
  179.         EQsingleColorStep();
  180.         delay(5 + irscale);
  181.         break;
  182.  
  183.     case 5:
  184.         EQvolbar();
  185.         delay(20);
  186.         break;  
  187.        
  188.     case 6:  
  189.        Strobe(30 + irscale); //30 is probably a functional minimum before it becomes just a dimmed light bulb, also I hate this mode
  190.        break;
  191.    
  192.     case 7:
  193.        rainbow();
  194.        delay(25);
  195.        break;
  196.        
  197.     case 8:
  198.         rainbowCycle(2);
  199.         delay(5 + irscale);
  200.         break;
  201.        
  202.     case 9:
  203.         rainbowCycleEQ(6);
  204.         delay(5 + irscale);
  205.         break;
  206.         //more modes can go in here, but change power function and mode change function accordingly.
  207.        
  208.     default:
  209.       //"off".. more or less.
  210.       break;
  211.   }
  212. }
  213.  
  214. // End main loop
  215.  
  216. //------------------ MODES ---------------------------
  217.  
  218. void Strobe(int msDelay){
  219.   // blasts out eyes with wanton disregard. No interaction
  220.   if(LoopStart + msDelay < millis()){        //Set the number of milliseconds for strobe on here
  221.     //Update the strip
  222.     if(StrobeOn){
  223.       colorFill(255, 255, 255);
  224.       StrobeOn = false;
  225.     }else{
  226.       colorFill(0, 0, 0);
  227.       StrobeOn = true;
  228.     }
  229.     //Setup for next loop
  230.     LoopStart = millis();
  231.   }
  232. }
  233.  
  234. void SlowWheel(int cchanged){
  235.   //SlowWheel uses a timer instead of a delay, fades can be imperceptibly slow
  236.   //cchanged is a color fill delay int, should be a high number otherwise why not just use wheel function.
  237.   if(LoopStart + cchanged < millis()){        //Set the number of milliseconds to wait for a color change here
  238.     Wheel(LoopCnt);
  239.     colorFill(ledRed, ledGreen, ledBlue);  
  240. //          Serial.print("CNT: "); // Debug -----------------------
  241. //          Serial.println(LoopCnt); // Debug -----------------------
  242.  
  243.     LoopCnt++;                           // Increment the wheel counter
  244.     if (LoopCnt >= 768){LoopCnt=0;}       // Counter at the end of wheel, move it back to 0
  245.     LoopStart = millis();                // Rest the timestamp
  246.   }
  247. }
  248.        
  249. void EQcenterBar(){
  250.   // reads eq and plugs RGB values directly into each consecutive pixel, mirrored from center.
  251.   if(LoopCnt <= PixelCountZB) {
  252.     readEQ();
  253.    
  254.     //Add new color to array at pointer position
  255.     leds[LoopCnt].r = ledRed;
  256.     leds[LoopCnt].g = ledGreen;
  257.     leds[LoopCnt].b = ledBlue;
  258.    
  259.     //now the opposite
  260.     leds[PixelCountZB - LoopCnt].r = ledRed;
  261.     leds[PixelCountZB - LoopCnt].g = ledGreen;
  262.     leds[PixelCountZB - LoopCnt].b = ledBlue;
  263.    
  264.     FastSPI_LED.show();  
  265.     LoopCnt++;    
  266.   }else{LoopCnt=0;}
  267. }
  268.  
  269.  
  270. void EQcolorOrgan(){
  271.   //reads eq, punches value into the whole strip at once
  272.   readEQ();
  273.   colorFill(ledRed, ledGreen, ledBlue);
  274. }
  275.  
  276. void FullFollow(){
  277.  //steps from one end of the array to the other updating EQ values pixel by pixel
  278.  readEQ();
  279.  
  280.  if(LoopCnt <= PixelCountZB) {
  281.     //Add new color to array at pointer position
  282.     leds[PixelCountZB - LoopCnt].r = ledRed; //not really sure why it's from this side
  283.     leds[PixelCountZB - LoopCnt].g = ledGreen;
  284.     leds[PixelCountZB - LoopCnt].b = ledBlue;      
  285.     LoopCnt++;  // Increment the array position
  286.     FastSPI_LED.show();
  287.   }else{LoopCnt = 0;}
  288. }  
  289.  
  290. void EQsingleColorStep(){//mod to include color RGB scales?
  291.  // this takes the three eq values and just shoves them into a single color's values three at a time.
  292.  // kinda lame, ill write it anyway. flag it for a remote control option to change colors or something.
  293.   readEQ();
  294.  
  295.   if (LoopCnt <= PixelCountZB ) {
  296.    
  297.     leds[LoopCnt].r = 0;
  298.     leds[LoopCnt].g = ledRed;
  299.     leds[LoopCnt].b = 0;
  300.     LoopCnt++;
  301.    
  302.     leds[LoopCnt].r = 0;
  303.     leds[LoopCnt].g = ledGreen;
  304.     leds[LoopCnt].b = 0;
  305.     LoopCnt++;
  306.    
  307.     leds[LoopCnt].r = 0;
  308.     leds[LoopCnt].g = ledBlue;
  309.     leds[LoopCnt].b = 0;
  310.     LoopCnt++;  
  311.    
  312.   } else {LoopCnt=0;}
  313.  
  314.   FastSPI_LED.show();
  315. }
  316.  
  317. void EQvolbar() {
  318. //EQ volume bar, each color has its own bar from the strip's center
  319. //I want the color to fade out towards the end, to keep center from just being white
  320. //something to do later.
  321.  
  322.   readEQ();
  323.  
  324.   memset(leds, 0, PixelCount * 3); //quickly wipe the array without touching variables
  325.    
  326.   int rngR = map(ledRed, 0, 256, 0, halfStripZB); //map the average to strip length, a bit sloppy, but i'm not smart enough to calculate once
  327.   int rngG = map(ledGreen, 0, 256, 0, halfStripZB);
  328.   int rngB = map(ledBlue, 0, 256, 0, halfStripZB);
  329.    
  330.   for(int i=0; i <= rngR; i++){
  331.       leds[halfStripZB-i].r = ledRed;
  332.       leds[halfStripZB+i].r = ledRed;
  333.   }
  334.  
  335.   for(int i=0; i <= rngG; i++){
  336.       leds[halfStripZB-i].g = ledGreen;
  337.       leds[halfStripZB+i].g = ledGreen;
  338.   }
  339.  
  340.   for(int i=0; i <= rngB; i++){    
  341.       leds[halfStripZB-i].b = ledBlue;
  342.       leds[halfStripZB+i].b = ledBlue;
  343.  
  344.   }
  345.   FastSPI_LED.show();
  346. }
  347.  
  348.  
  349. void rainbow() {
  350.   // rainbow accepts a color change delay value and fades the wheel color by color pixel by pixel
  351.   // I pulled out the loop so that the IR and button checks were performed every cycle
  352.   // also uses LoopCnt global variable. the wheel equation scales the entire strip to a 0-255 value based
  353.   // on the position of the pixel and the position of the loop count (which offsets the wheel's start position)
  354.      
  355.   if(LoopCnt <= 767) {
  356.     for (int i=0; i < PixelCountZB; i++) {
  357.       Wheel( (i + LoopCnt) % 767 );
  358.       leds[i].r = ledRed;
  359.       leds[i].g = ledGreen;
  360.       leds[i].b = ledBlue;
  361.     }  
  362.     LoopCnt++;
  363.     FastSPI_LED.show();
  364.   }else{LoopCnt=0;}
  365. }
  366.  
  367.  
  368. void rainbowCycle(long stripFades) { //stripfades should be an int, long keeps big number errors at bay
  369. //The confusingly named rainbowcycle attempts to evenly split the rainbow fade values along the LED strip
  370. //stripFades stripfades is the number of fades across the strip, I don't fully understand the equation here
  371. //and I had to make it used floating point calculation, so it runs slow. Adapted from adafruit's library.
  372.  
  373.   if(LoopCnt <= 767) {
  374.     for (int i=0; i < PixelCountZB; i++) {
  375.       Wheel( ((i * (256 * stripFades) / PixelCount) + LoopCnt) % 767); //loopcnt handles the offset, while i splits 255 evenly among the pixel count
  376.       leds[i].r = ledRed;
  377.       leds[i].g = ledGreen;
  378.       leds[i].b = ledBlue;
  379.     }  
  380.     LoopCnt++;
  381.     FastSPI_LED.show();
  382.   }else{LoopCnt=0;}
  383. }
  384.  
  385. void rainbowCycleEQ(long stripFades) {
  386. // Lowers the brightness values of rainbow cycle and uses the EQ color values to make up the difference.
  387. // short strips of colors travel down the pixels, and get larger as volume increases fading into
  388. // each other. it may look better if the effect is massively slowed or augmented in some way, color
  389. // interaction is hard to see.
  390.   int red, green, blue;
  391.  
  392.   if(LoopCnt <= 767) {
  393.     readEQ(); //one eq value per loop, keeps things from gettng wacky.
  394.    
  395.     red = ledRed - 200;  //instead of halving and then adding im taking these into the negatives.
  396.     green = ledGreen - 200;
  397.     blue = ledBlue - 200;
  398.    
  399.     for (int i=0; i < PixelCountZB; i++) {
  400.       Wheel( ((i * (256 * stripFades) / PixelCount) + LoopCnt) % 767 ); //the fade number is float otherwise int is overloaded... probably very slow
  401.       leds[i].r = constrain(ledRed + red, 0, 255); //this is a dumb way to boost bass, I just need a better input
  402.       leds[i].g = constrain(ledGreen + green, 0, 255);
  403.       leds[i].b = constrain(ledBlue + blue, 0, 255);
  404.     }
  405.  
  406.     LoopCnt++;
  407.     FastSPI_LED.show();
  408.   }else{LoopCnt=0;}
  409. }
  410.  
  411. // ----------------------- Color Support Functions -----------------------
  412.  
  413. void colorWipe(int red, int green, int blue) {
  414. // Used to open up loops, RGB values write to pixel set by loop count, strip is then displayed
  415. // Each call of the function advances pixel count.
  416.   if(LoopCnt <= PixelCountZB) {
  417.     leds[LoopCnt].r = red;
  418.     leds[LoopCnt].g = green;
  419.     leds[LoopCnt].b = blue;
  420.     LoopCnt++;                           // Increment the counter
  421.     FastSPI_LED.show();   // write all the pixels out
  422.   }else{LoopCnt=0;}
  423. }
  424.  
  425. void colorWipeBack(int red, int green, int blue, uint8_t wait) {
  426.  // Used to open up loops, RGB values write to pixel set by loop count, strip is then displayed
  427.  // Each call of the function LOWERS pixel count.
  428.   if(LoopCnt <= PixelCountZB) {
  429.     leds[PixelCountZB - LoopCnt].r = red;
  430.     leds[PixelCountZB - LoopCnt].g = green;
  431.     leds[PixelCountZB - LoopCnt].b = blue;
  432.     LoopCnt++;                           // Increment the counter
  433.     FastSPI_LED.show();   // write all the pixels out
  434.   }else{LoopCnt=0;}
  435. }
  436.  
  437.  
  438. void colorFill(int red, int green, int blue) {
  439.  //makes a filled array of the chosen color all at once (resets pixel count), then writes it.
  440.   for (int i=0; i < PixelCount; i++) { //is there a more direct way to pass these? this works.
  441.     leds[i].r = red;
  442.     leds[i].g = green;
  443.     leds[i].b = blue;
  444.   }
  445.   FastSPI_LED.show();
  446. }
  447.  
  448. void Wheel(int WheelPos){
  449. //wheel accepts 0-767 (0 biased I guess) position int, it sets the global ledRed, ledGreen and ledBlue
  450. //values based on this position value. each color gets 256 positions. wheelpos binary number is
  451. //split to thirds by the bit shift.
  452.   switch(WheelPos >> 8)
  453.   {
  454.     case 0:
  455.       ledRed = 255 - WheelPos % 256;   //Red down
  456.       ledGreen = WheelPos % 256;      // Green up
  457.       ledBlue = 0;                  //blue off
  458.       break;
  459.     case 1:
  460.       ledGreen = 255 - WheelPos % 256;  //green down
  461.       ledBlue = WheelPos % 256;      //blue up
  462.       ledRed = 0;                  //red off
  463.       break;
  464.     case 2:
  465.       ledBlue = 255 - WheelPos % 256;  //blue down
  466.       ledRed = WheelPos % 256;      //red up
  467.       ledGreen = 0;                  //green off
  468.       break;
  469.   }
  470. }
  471.  
  472. void readEQ() {
  473.   //read the values from the MSGEQ7
  474.   digitalWrite(resetPin, HIGH);
  475.   digitalWrite(resetPin, LOW);
  476.  
  477.   for (int q = 0; q < 7; q++)
  478.   {
  479.     digitalWrite(strobePin, LOW);
  480.     delayMicroseconds(30); // to allow the output to settle
  481. //   spectrumValue[q] = smooth(analogRead(analogPin), billyD, spectrumValue[q]); //may take too long
  482.     spectrumValue[q] = analogRead(analogPin);
  483. //  Serial.print(q);
  484. //  Serial.print(" ");
  485. //  Serial.println(spectrumValue[q]);
  486.     digitalWrite(strobePin, HIGH);
  487.   }
  488.  
  489.   //Set the LED Colors
  490.   //this takes the analog frequency values and averages some bands
  491.   //the values are then set zero if not above a noise level, then mapped
  492.   //from their 0-1024 value to 1-255
  493.  
  494.   ledBlue = max(spectrumValue[6], spectrumValue[5]);
  495.   if (ledBlue <= noiseLvl){
  496.     ledBlue=0;
  497.   }else{
  498.     ledBlue = map(ledBlue, noiseLvl, 1024, 1, 255);
  499.   }
  500.  
  501.   ledGreen = spectrumValue[4]; //4 is crazy, its like 3x higher than everything else... probably my mic.
  502.   if (ledGreen <= noiseLvl){
  503.     ledGreen=0;
  504.   }else{
  505.     ledGreen = map(ledGreen, noiseLvl, 1024, 1, 255);
  506.   }
  507.   ledRed = max(spectrumValue[3], max(spectrumValue[2], max(spectrumValue[1], spectrumValue[0]))); //kind of out of control with the max functions, but red isnt showing enough!
  508.   if (ledRed <= noiseLvl){
  509.     ledRed=0;
  510.   }else{
  511.     ledRed = map(ledRed, noiseLvl, 1024, 1, 255);
  512.   }
  513. }
  514.  
  515. void checkButton(int debounce){
  516.     // read the pushbutton input pin:
  517.   buttonState = digitalRead(buttonPin);
  518.  
  519.  
  520.   if (buttonState == HIGH) {
  521.     // Wait a bit then check again to be sure
  522.     delay(debounce);
  523.     buttonState = digitalRead(buttonPin);
  524.     if (buttonState == HIGH) {
  525.       ChangeMode(true); //The button was pressed, change the mode
  526.     }
  527.   }
  528. }
  529.  
  530.  
  531. void ChangeMode(boolean ModeUP) {
  532. //incrament the mode and recycle if at full
  533. //I can't wait to get the xbox remote running and delete this function
  534.   if (ModeUP){
  535.     digitalWrite(statusPin, LOW);
  536.     mode++;
  537.     if (mode > 9) {digitalWrite(statusPin, LOW); mode = 0;}
  538.   }else{
  539.     digitalWrite(statusPin, LOW);
  540.     mode--;
  541.     if (mode < 0) {digitalWrite(statusPin, LOW); mode = 9;}
  542.   }
  543.  
  544.   // Clear the strip
  545.   memset(leds, 0, PixelCount * 3);
  546.   FastSPI_LED.show();
  547.  
  548.   LoopStart = 0; //reset time
  549.   delay(20);   //dont like it, but otherwise the LED might not be visible, and modes already change too quickly
  550.   digitalWrite(statusPin, HIGH);
  551. }
  552.  
  553.  
  554. void checkIR(){
  555.   if (irrecv.decode(&results)) {
  556. //    Serial.println(results.value);       // Debug
  557. //    Serial.println(results.value >> 32, HEX); //Debug Xbox
  558. //    Serial.println(results.value, HEX);       //Debug Xbox
  559. //    in the ifs the IR code also gets & ~0x8000LL in order to handle the flipped bit from every other press, haven't tested though.
  560.  
  561.     switch (results.value) {
  562.       case IRCode_NEXT:
  563.         ChangeMode(true);
  564.         break;
  565.        
  566.       case IRCode_PREV:
  567.         ChangeMode(false);
  568.         break;
  569.  
  570.       case IRCode_PWR:
  571.          mode = 10; //bump it out to default
  572.          memset(leds, 0, PixelCount * 3);
  573.          FastSPI_LED.show();
  574.          break;
  575.          
  576.        case IRCode_PLAY:
  577.          irscale = constrain(irscale + 5, 0, 1000);
  578.        break;
  579.        
  580.        case IRCode_STOP:
  581.          irscale = constrain(irscale - 5, 0, 1000);
  582.        break;
  583.        
  584.     }
  585.     irrecv.resume(); // Receive the next value
  586.   }
  587. }
  588.  
  589. int smooth(int data, float filterVal, float smoothedVal){
  590. //with all the glorious computational overhead I decide to swipe a value smoother from
  591. //http://arduino.cc/playground/Main/Smooth I guess this could help out.
  592.  
  593.  // filterVal = constrain(filterVal, 0, .99);    //make sure param's are within range
  594.   smoothedVal = (data * (1 - filterVal)) + (smoothedVal  *  filterVal);
  595.   return (int)smoothedVal;
  596. }
clone this paste RAW Paste Data