Guest User

FastLED FHT Bug

a guest
Oct 26th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. /*
  2. fht_adc.pde
  3. guest openmusiclabs.com 9.5.12
  4. example sketch for testing the fht library.
  5. it takes in data on ADC0 (Analog0) and processes them
  6. with the fht. the data is sent out over the serial
  7. port at 115.2kb.  there is a pure data patch for
  8. visualizing the data.
  9. */
  10.  
  11. #define LOG_OUT 1 // use the log output function
  12. #define FHT_N 256 // set to 256 point fht
  13.  
  14. #include <FHT.h> // include the library
  15. #include <FastLED.h>
  16.  
  17. #define ledPin 10
  18. #define numLeds 23
  19. CRGB leds[numLeds];
  20.  
  21. void setup() {
  22.   Serial.begin(115200); // use the serial port
  23.   TIMSK0 = 0; // turn off timer0 for lower jitter
  24.   ADCSRA = 0xe5; // set the adc to free running mode
  25.   ADMUX = 0x40; // use adc0
  26.   DIDR0 = 0x01; // turn off the digital input for adc0
  27.  
  28.   LEDS.addLeds<WS2812B, ledPin, GRB>(leds, numLeds).setCorrection(TypicalSMD5050);
  29.  
  30. }
  31.  
  32. void loop() {
  33.   static byte hue = 0;
  34.  
  35.   while(1) { // reduces jitter
  36.     cli();  // UDRE interrupt slows this way down on arduino1.0
  37.     for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
  38.       while(!(ADCSRA & 0x10)); // wait for adc to be ready
  39.       ADCSRA = 0xf5; // restart adc
  40.       byte m = ADCL; // fetch adc data
  41.       byte j = ADCH;
  42.       int k = (j << 8) | m; // form into an int
  43.       k -= 0x0200; // form into a signed int
  44.       k <<= 6; // form into a 16b signed int
  45.       fht_input[i] = k; // put real data into bins
  46.     }
  47.     fht_window(); // window the data for better frequency response
  48.     fht_reorder(); // reorder the data before doing the fht
  49.     fht_run(); // process the data in the fht
  50.     fht_mag_log(); // take the output of the fht
  51.     sei();
  52.  
  53.     /*
  54.     // this causes an r28 and r29 cannot be used in asm here error
  55.     for(int i = 0;i<numLeds;i++)
  56.     {
  57.       leds[i] = CHSV(fht_log_out[i],255,255);
  58.       LEDS.show();
  59.     }
  60.  
  61.     // this causes an r28 and r29 cannot be used in asm here error
  62.     for(int i = 0;i<numLeds;i++)
  63.     {
  64.       leds[i] = CHSV(hue++,255,255);
  65.       LEDS.show();
  66.     }
  67.     */
  68.    
  69.     // this seems to work fine.
  70.     for(int i = 0;i<numLeds;i++)
  71.     {
  72.       leds[i] = CRGB::Red;
  73.       LEDS.show();
  74.     }
  75.  
  76.     // this seems to work fine.
  77.     for(int i = 0;i<numLeds;i++)
  78.     {
  79.       Serial.print(fht_log_out[i]);
  80.       Serial.print(".");
  81.     }
  82.     Serial.println();
  83.  
  84.      // send out the data
  85.   }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment