attach 4 URM37 range finders and 2 shiftregisters PWM to an arduino duemilanove

Hi all,

For a school project I am trying to attach four URM37 v3.2 range finders and 13 LEDs to an arduino duemilanove. I use two libraries, one for the range finders made by Miles Burton MilesBurton.com, and one for the shiftregisters so I can use PWM for the LEDs made by Elco Jacobs http://www.elcojacobs.com/shiftpwm/.

I want the LEDs to be the brightest the closest to the range finder that measures the smallest distance. The LEDs further away from this range finder should be increasingly dimmed.

Now the program works fine when I use only the ShiftPWM library and want to define the brightness of the LEDs, but whenever I include the library of Miles Burton and read the range finders the LEDs start to blink. But only the ones that are put on via an array.

Here is the code I used to find the problem. I use one range finder (URM37 v3.2), 2 shiftregisters(4HC595N) and 13 LEDs.
The LEDs turned to a specific brightness that is not 0 or 255 blink when the range finder is used.
Can anyone tell me what I can do to make this stop? One of the people here said it might be the use of a timer within both the libraries, how do I know if this is true and how can I change this?

#include <SPI.h>            //from library ShiftPWM
#include "hsv2rgb.h"       //from library ShiftPWM
#include "URMSerial.h"    //from library URM37

//Data pin is MOSI (atmega168/328: pin 11. Mega: 51) 
//Clock pin is SCK (atmega168/328: pin 13. Mega: 52)
const int ShiftPWM_latchPin=8;
const bool ShiftPWM_invertOutputs = 0; // if invertOutputs is 1, outputs will be active low. Usefull for common anode RGB led's.

#include <ShiftPWM.h>   // include ShiftPWM.h after setting the pins!

unsigned char maxBrightness = 255;    //used for the ShiftPWM
unsigned char pwmFrequency = 75;     //used for the ShiftPWM
int numRegisters = 2;                       //used for the ShiftPWM

#define DISTANCE 1                          //define measurements for the URM37
#define TEMPERATURE 2
#define ERROR 3
#define NOTREADY 4
#define TIMEOUT 5

URMSerial urm;

void setup()   {                
  pinMode(ShiftPWM_latchPin, OUTPUT);  
  SPI.setBitOrder(LSBFIRST);
  // SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte. 
  // SPI transfer and calculations overlap for the other bytes.
  SPI.setClockDivider(SPI_CLOCK_DIV4); 
  SPI.begin(); 

  Serial.begin(9600);
  
  urm.begin(6,7,9600);         //attache one URM37 range finder

  ShiftPWM.SetAmountOfRegisters(numRegisters);
  ShiftPWM.Start(pwmFrequency,maxBrightness);  
}

void loop()
{  
  Serial.println("Measurement: ");         //get and print the measurement from the range finder, if I turn this on the LEDs start to blink
  Serial.println(getMeasurement());

  //Setting all 13 LEDs at a specific brightness to start with (0 is off, 255 is max on)
  ShiftPWM.SetOne(0,0);          //not attached
  //ShiftPWM.SetOne(1,0);          //
  //ShiftPWM.SetOne(2,255);          //NO corner
  //ShiftPWM.SetOne(3,0);          //N side
  ShiftPWM.SetOne(4,0);
  ShiftPWM.SetOne(5,0);          //ZO corner
  ShiftPWM.SetOne(6,0);          //W side
  ShiftPWM.SetOne(7,0);          //not attached
  ShiftPWM.SetOne(8,0);          //not attached
  ShiftPWM.SetOne(9,0);          //ZW corner
  //ShiftPWM.SetOne(10,0);         //O side
  ShiftPWM.SetOne(11,0);         //
  ShiftPWM.SetOne(12,0);         //middle
  ShiftPWM.SetOne(13,15);         //Z side              //blinks when range finder is used
  ShiftPWM.SetOne(14,15);         //                      //blinks when range finder is used
  ShiftPWM.SetOne(15,255);         //NW corner
  
  //setting 4 specific LEDs to specific brightnesses through an array, these LEDs will start to blink when the range finder is used.
  int ledPin[4] =      { 10 , 1 , 3 , 2 };
  unsigned char ledValue[4] =    { 5 , 10 , 15 , 50 };

  for(int i=0; i<4; i++)
  {
    if( ledPin[i] >= 0 )
    {
      ShiftPWM.SetOne(ledPin[i],ledValue[i]);
      //ShiftPWM.SetOne(2,ledValue[i]);
    }
  }
}
  
//function get the range finders measurement (from Miles Burton's library)
int value;
int getMeasurement()
{
  // Request a distance reading from the URM37
  switch(urm.requestMeasurementOrTimeout(DISTANCE, value)) // Find out the type of request
  {
  case DISTANCE: // Double check the reading we recieve is of DISTANCE type
    //    Serial.println(value); // Fetch the distance in centimeters from the URM37
    return value;
    break;
  case TEMPERATURE:
    return value;
    break;
  case ERROR:
    Serial.println("Error");
    break;
  case NOTREADY:
    Serial.println("Not Ready");
    break;
  case TIMEOUT:
    Serial.println("Timeout");
    break;
  } 

  return -1;
}

i'm not exactly sure about what you make, but i read you use several led's.
While you configured only 1 led for output in the setup part.
If you dont configure a port as output, some resistor will kick in, and a led will only glow weak.
So, if you want your led's to shine configure them as output (like you did with that one led)

i personally prefer to set a range lof leds like this

int leds[] = {4,5,6,7,8,9,10,11,12,13}
for (int i=0;i<10;i++){pinMode(leds*, OUTPUT);} *
so i=0 will be your first led (and the array determines which array it is)