* MP3 Shield * - Rogue Robotics rMP3

@jennyc: Here is an example I wrote. In my case, I am using a LEDHead with LEDs to display output.

#include <RogueMP3.h>
#include <NewSoftSerial.h>

NewSoftSerial rmp3_s(6, 7);

RogueMP3 rmp3(rmp3_s);

#define numberOfBands 3
uint16_t bandfreqs[] = { 120, 2000, 20000 };
//uint8_t outputPin[] = { 2, 3, 4 };
uint8_t outputPin[] = { 29, 30, 31 };

#define THRESHOLD 12

#define songname "/001.mp3"


void checkFrequencies(void)
{
  // prepare for up to 23 bands
  uint8_t v[23];

  rmp3.getspectrumanalyzer(v);

  for (uint8_t i=0; i<numberOfBands; i++)
  {
    if (v[i] > THRESHOLD)
      digitalWrite(outputPin[i], HIGH);
    else
      digitalWrite(outputPin[i], LOW);
  }
}


void setup(void)
{
  Serial.begin(9600);
  Serial.println("Started");

  rmp3_s.begin(9600);

  for (uint8_t i = 0; i < numberOfBands; i++)
    pinMode(outputPin[i], OUTPUT);

  Serial.println("Starting sync");
  rmp3.sync();
  Serial.println("Done sync");
}


void playTrack(void)
{
  Serial.println("Playing Track");
 
  rmp3.playfile(songname);

  rmp3.setspectrumanalyzer(bandfreqs, numberOfBands);
}

int8_t isPlaying(void)
{
  return (rmp3.getplaybackstatus() == 'P' ? 1 : 0);
}


void loop(void)
{
  if (!isPlaying())
    playTrack();

  checkFrequencies();
}

You'll definitely have to have different thresholds for each band, since they will have different responses.

b