Go Down

Topic: Using serial data from winamp plugin to drive LED visualization (Read 1 time) previous topic - next topic

jbud

Hello, I found an earlier topic and I'd love to share what I learned there.

The topic:

http://forum.arduino.cc/index.php?topic=40078.0

I modified the suggested code as well as the plugin. All the info is on my github here:

https://github.com/jbud/FastLED-Serial-Music-Arduino

I was sad to see that topic died 5 years ago, but maybe I can revive it and get some help refining my code.

obart

There where a number of problens in your code, producing buffer overflows and making the whole 10 specbins quite unuseable:

here the corrected code snippet with the modified serial parser:
#include "FastLED.h"
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define COLOR_ORDER GBR // Reversed for styling. My default is GBR

#define BRIGHTNESS          36
#define FRAMES_PER_SECOND  120 // This limit can improve performance and reduce the chance of overflow lag.
#define AVG                0

uint8_t gHue = 0;
uint8_t gOffset = 0;
byte temp;
byte DataValid = 0;
byte DataCounter = 0;

#define NUM_STRIPS 4
#define NUM_LEDS_PER_STRIP 50
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS

CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];

// For mirroring strips, all the "special" stuff happens just in setup.  We
// just addLeds multiple times, once for each strip
void setup() {
 // tell FastLED there's 60 NEOPIXEL leds on pin 10, starting at index 0 in the led array
 FastLED.addLeds<INK1003, 6, RGB>(leds, 0, NUM_LEDS_PER_STRIP);

 // tell FastLED there's 60 NEOPIXEL leds on pin 11, starting at index 60 in the led array
 FastLED.addLeds<INK1003, 5, RGB>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);

 // tell FastLED there's 60 NEOPIXEL leds on pin 12, starting at index 120 in the led array
 FastLED.addLeds<INK1003, 4, RGB>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
 FastLED.addLeds<INK1003, 3, RGB>(leds, 3 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
 FastLED.setBrightness(255);
 Serial.begin(57600);
 
}
void rainbow()
{
 fill_rainbow( leds, 10, gHue, 0); // Create a rainbow and adjust based on global hue.
}
byte limit(byte in) {
 if (in > 128) {
   temp = in - 127;
   temp = temp * 2;
 }
 else {
   temp = 0;
 }
 return round(in); // Bypassing this function until better math is performed... -_-
}
int lvl = 1;      // Level of spectrum to analyze
byte data[10];      // raw serial data array
int isData = 0;
byte idx = 0;
uint16_t averg = 0;
byte processedData = 0;
void loop() {
 if (Serial.available() > 0) {
   byte i = Serial.read();
   if (!DataValid) {
      if (i == 255)
      DataValid = true;
      DataCounter = 0;
   }
   else{
     if (DataCounter < 10)
     {
        data[DataCounter++] = i; //Fill Buffer    
     }
     else {
     idx = 0; //gOffset; //set startvalue  
        for (int j = 0; j < NUM_LEDS ; j++){
           leds[idx++] = CHSV(map(j,0,NUM_LEDS-1, 0, 255), 255, data[map(j,0,NUM_LEDS-1,0,9)]);
           if (idx==NUM_LEDS) { //rotate spectrum
             idx = 0;
           }
        }
   //rainbow();
   FastLED.show();
   DataValid = false;    
   //EVERY_N_MILLISECONDS( 40 ) {
   gOffset++;
   if (gOffset==NUM_LEDS) {
    gOffset = 0;}
   //}
    }
   }
 }
}

As you see, no waiting at all. Waiting is introduced by waiting for serial data, but as soon as that is received it has to be processed.
No Bytes are read without taking care that they are available, but as the buffer is very small, I start reading as soon as there is just one byte and skip until I find the start marker '255'.

I had to remove the rainbow for the idle mode because I was not too interested in it.

I have my own fastled version with these rare INK1003 chips. Change them to what ever you use.

Sorry for the short reply, its rather late already...

BR
Oliver

dinoelectro

hi was trying connect plugin with arduino but i dont get track info, but i get spectrumn analyzer info

more info is here

https://dinoelectro.blogspot.com/

Go Up