Power issue?

Hi,
I'm using a Duemilanove and WAV Shield connected to some small headphones and a MaxSonar - EZ1 to act like a doorbell. This works fine.
I also want to turn on an led and have them hooked up through a 3906 transistor and a 9 volt battery.
The light only comes on when the WAV shield is playing and doesn't stay on . Ideally I want the light to stay on for 30 seconds or so, but am just trying to get it to stay on for now.
Is this a power or coding issue?
Thanks.

#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
#define ledPin 12

int i;
int x=0;
int y=0;
int distsensor=0;
int pread=0;
int county=0;
int counttime=0;
int prevcounttime=0;
int xy=0;
int lo=0;

AF_Wave card;
File f;
Wavefile wave;      // only one!
#define redled 9
uint16_t samplerate;

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Wave test!");
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(redled, OUTPUT);
  ;

  if (!card.init_card()) {
    putstring_nl("Card init. failed!"); 
    return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); 
    return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); 
    return;
  }

  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); 
    return;
  }

  putstring_nl("Files found:");
  ls();
}

void ls() {
  char name[13];
  int ret;
  card.reset_dir();
  putstring_nl("Files found:");
  while (1) {
    ret = card.get_next_name_in_dir(name);
    if (!ret) {
      card.reset_dir();
      return;
    }
    Serial.println(name);
  }
}

uint8_t tracknum = 0;

void loop() { 
   x++;
   if(x>=10000)
{
 // digitalWrite(ledPin, LOW);
  x=0;
}
if (lo==1)
{
  digitalWrite(ledPin, HIGH);
}
  uint8_t i, r;
  char c, name[15];
  card.reset_dir();

  for (i=0; i<5; i++) {
    distsensor += analogRead(5);
    delay(5);
  }
  distsensor /= 6;
  //digitalWrite(ledPin, LOW);
  Serial.print("Sensor = ");
  Serial.println(distsensor);
  Serial.print("Hits = ");
  Serial.println(x);

  delay(5);
  // if (pread < (distsensor -8) || pread > (distsensor +8))
  if (pread > (distsensor +8))
  {
    if (y!=1 || prevcounttime +50 <= counttime)// Ignore first time through as sensors stabilize y=0;
    {
      //digitalWrite(ledPin, LOW);
      y=1;
      delay(10);
    }

    digitalWrite(ledPin, HIGH);
    lo =1;
    x++;
    prevcounttime=counttime;
    counttime=0;
    Serial.println("in loop..... ");
    Serial.write("xy = ");
    Serial.println(xy);

    playcomplete("1MEMO.WAV");


    // add counttime=0;
    //county=x/2;// try ceil or floor? to round up
    county=ceil(x/2);
    delay(5);
  }
  pread=distsensor;
  counttime++;
  if (counttime >=50000)
  {
    counttime=0;
  }

}


void playcomplete(char *name) {
  uint16_t potval;
  uint32_t newsamplerate;
  tracknum++;
  playfile(name);
  Serial.write ("Playing ");
  Serial.write(name);
  samplerate = wave.dwSamplesPerSec;
  while (wave.isplaying) {     
    // you can do stuff here!
    //  delay(5);
  }
  card.close_file(f);
}

void playfile(char *name) {
  f = card.open_file(name);
  if (!f) {
    putstring_nl(" Couldn't open file"); 
    return;
  }
  if (!wave.create(f)) {
    putstring_nl(" Not a valid WAV"); 
    return;
  }
  // ok time to play!
  wave.play();

}

Which LED are you having issues with? The one attached to ledPin or the one attached to redled?

Pin 12 the ledPin.

It looks like you turn the LED on before the call to playcomplete. I see nothing in playcomplete that turns it off, and playcomplete does not return until the wav file has completed playing.

Is this what you are seeing?

Some comments in the code would be helpful, as well as meaningful names for variables. county doesn't mean anything. What are you counting, and why?

What pins does the wave shield use?

Thanks. It was the pin I was using. I've got it now.