2Pots controling LEDs using 2 74hc595 ShiftRegistr

Hello folks!

This is my first post, so please be gentle.

I am using an Arduino Duemilanove. I have 2 potentiometers conected to analog inputs 0,1. I also have 2 74hc595 shift registers connected. The 2 shift registers have 8 LEDs each on their respective Q0-Q7 pins.

I am trying to make each shift register change the lit LEDs on one of the shift registers. One pot for one register the other pot for the other register. As you turn the pot the lit LED goes from the lowest value 1 to the highest value 8.

The problem I am having is that both pots are controlling both sets of LEDs. This is probably stemming from me hacking together different sources of code and duplicating certain parts to fit in to both registers.

Any help and guidance is appreciated.

Below is the code I am working with.

/*
 Scrolling LEDs


 This sketch reads 2 seperate analog inputs from 2 seperate potentiometers and uses their values 
 to scroll across 8 LEDs controlled by 2 74HC595 shift registers. Each shift register coresponds to a Pot.

 Hardware:
 *2 x 74HC595 shift registers attached to pins 4, 6, and 7  and 8,11,12 of the Arduino,
 as detailed below.
 * LEDs attached to each of the outputs of the shift register
 *2 x 10k Pots connected to analog inputs 0,1.
 
 Note that for some reason I labeled one of the shift registers 0 and the other 1. I dont know why.
 
 Compiled Dec 10, 2010
 
@@@ All borrowed code credited at bottom @@@
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPin0 = A0;  // Analog input pin that potentiometer 0 is attached to
const int analogInPin1 = A1;  // Analog input pin that potentiometer 1 is attached to

// The steps to reach each LED
const int stepZero  = 31;
const int stepOne   = 62;
const int stepTwo   = 93;
const int stepThree = 124;
const int stepFour  = 155;
const int stepFive  = 186;
const int stepSix   = 217;
const int stepSeven = 248;
const int stepEight = 255;

int sensorValue0 = 0;        // value read from pot 0
int outputValue0 = 0;        // value output from pot 0
int sensorValue1 = 0;        // value read from pot 1
int outputValue1 = 0;        // value output from pot 1

//Pin connected to latch pin (ST_CP) of 74HC595 #0
const int latchPin0 = 8;
//Pin connected to clock pin (SH_CP) of 74HC595 #0
const int clockPin0 = 12;
////Pin connected to Data in (DS) of 74HC595 #0
const int dataPin0 = 11;

//Pin connected to latch pin (ST_CP) of 74HC595 #1
const int latchPin1 = 4;
//Pin connected to clock pin (SH_CP) of 74HC595 #1
const int clockPin1 = 6;
////Pin connected to Data in (DS) of 74HC595 #1
const int dataPin1 = 7;

void setup() {
   // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin0, OUTPUT);
  pinMode(dataPin0, OUTPUT);  
  pinMode(clockPin0, OUTPUT);
  pinMode(latchPin1, OUTPUT);
  pinMode(dataPin1, OUTPUT);  
  pinMode(clockPin1, OUTPUT);
  Serial.begin(9600);
  Serial.println("reset");
}

void loop() {
  // read the analog in value:
  sensorValue0 = analogRead(analogInPin0);            
  // map it to the range of the analog out:
  outputValue0 = map(sensorValue0, 0, 1023, 0, 255);
  // read the analog in value:
  sensorValue1 = analogRead(analogInPin1);            
  // map it to the range of the analog out:
  outputValue1 = map(sensorValue1, 0, 1023, 0, 255);  
     

  // print the results to the serial monitor:
  Serial.print("sensor 0= " );                       
  Serial.print(sensorValue0);      
  Serial.print("\t output 0= ");      
  Serial.println(outputValue0);   
  
  Serial.print("sensor 1= " );                       
  Serial.print(sensorValue1);      
  Serial.print("\t output 1= ");      
  Serial.println(outputValue1);
  
  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(10);               
  
  
  // if, else if statements checking at what value that Pot 0 is at 
  // Each value range coresponds with a LED
  if (outputValue0 <= stepZero) {
    int bittoset0 = 0;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
  else if (outputValue0 <= stepOne) {
    int bittoset0 = 1;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
  else if (outputValue0 <= stepTwo) {
    int bittoset0 = 2;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
   else if (outputValue0 <= stepThree) {
    int bittoset0 = 3;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
  else if (outputValue0 <= stepFour) {
    int bittoset0 = 4;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
   else if (outputValue0 <= stepFive) {
    int bittoset0 = 5;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
   else if (outputValue0 <= stepSix) {
    int bittoset0 = 6;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
  else if (outputValue0 <= stepSeven) {
    int bittoset0 = 6;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }
  else if (outputValue0 <= stepEight) {
    int bittoset0 = 6;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset0, HIGH);
  }

  // if, else if statements checking at what value Pot 1 is at 
  // Each value range coresponds with a LED
  if (outputValue1 <= stepZero) {
    int bittoset1 = 0;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
  else if (outputValue1 <= stepOne) {
    int bittoset1 = 1;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
  else if (outputValue1 <= stepTwo) {
    int bittoset1 = 2;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
   else if (outputValue1 <= stepThree) {
    int bittoset1 = 3;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
  else if (outputValue1 <= stepFour) {
    int bittoset1 = 4;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
   else if (outputValue1 <= stepFive) {
    int bittoset1 = 5;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
   else if (outputValue1 <= stepSix) {
    int bittoset1 = 6;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
  else if (outputValue1 <= stepSeven) {
    int bittoset1 = 6;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
  else if (outputValue1 <= stepEight) {
    int bittoset1 = 6;

  // write to the shift register with the correct bit set high:
    registerWrite(bittoset1, HIGH);
  }
}
// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
// the bits you want to send
  byte bitsToSend0 = 0;
  byte bitsToSend1 = 0;

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin0, LOW);
  digitalWrite(latchPin1, LOW);
  
  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend0, whichPin, whichState);
  bitWrite(bitsToSend1, whichPin, whichState);
  
  // shift the bits out:
  shiftOut(dataPin0, clockPin0, MSBFIRST, bitsToSend0);
  shiftOut(dataPin1, clockPin1, MSBFIRST, bitsToSend1);

    // turn on the output so the LEDs can light up:
  digitalWrite(latchPin0, HIGH);
  digitalWrite(latchPin1, HIGH);
}

/*
  Shift Register Example
 for 74HC595 shift register

 This sketch turns reads serial input and uses it to set the pins
 of a 74HC595 shift register.

 Hardware:
 * 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino,
 as detailed below.
 * LEDs attached to each of the outputs of the shift register

 Created 22 May 2009
 Created 23 Mar 2010
 by Tom Igoe

-------------------------------------------------------------------------------
  Analog input, analog output, serial output
 
 Reads an analog input pin, maps the result to a range from 0 to 255
 and uses the result to set the pulsewidth modulation (PWM) of an output pin.
 Also prints the results to the serial monitor.
 
 The circuit:
 * potentiometer connected to analog pin 0.
   Center pin of the potentiometer goes to the analog pin.
   side pins of the potentiometer go to +5V and ground
 * LED connected from digital pin 9 to ground
 
 created 29 Dec. 2008
 Modified 4 Sep 2010
 by Tom Igoe
 
 This example code is in the public domain.
 
 */
const int stepZero  = 31;
const int stepOne   = 62;
const int stepTwo   = 93;
const int stepThree = 124;
const int stepFour  = 155;
const int stepFive  = 186;
const int stepSix   = 217;
const int stepSeven = 248;
const int stepEight = 255;

Take a peek here: http://arduino.cc/en/Reference/Array
This could be done with one line of code. It would make much of the rest of your program easier, too.

const int steps[] = {31, 62, 63, 124, 155, 186, 217, 248, 255};
  outputValue0 = map(sensorValue0, 0, 1023, 0, 255);

No. While this works, it’s a waste of time and memory.

outputValue0 = sensorValue0/4;

Same result. Much faster.

This is probably stemming from me hacking together different sources of code and duplicating certain parts to fit in to both registers.

You are writing the same value to each shift register. You need to modify registerWrite() to take 3 arguments - the register to write to, which pin to write to, and the value to write to that pin.