Shift register qeustion suspect i have lack of fundamental knowledge

Hello everyone , i want to say first of all hello , im a new arduino programmer based in the UK , i have programmed before mainly in visual basic

im having a problem using shift registers but it also raises a question about how to do something which i can see is of fundamental importance

i am trying to control the outputs of two shift registers , the shift registers are connected ok and work ok with the arduino shift out demo code

i am trying to use an array to control the registers so its easy for me to port my applications over to the outputs on the shift register chips

now what i understand is that you send 16 bytes to the chips and the relevant outputs get switched on and off , i also realise that this is how you write to the outputs in the other microcontrollers using base level programming and not the arduino bootloader which makes it easier by being able to address each output , so how do you build your 16 bytes on the fly , say if i want to just change one of the outputs , i cant imagine that you have a lookup table of each hex code for any given combination of ons and offs it just wouldnt make sense to do it like that . im trying to use an array and a loop to build up the 16 bits and then send it out to the chips just im not having much success , i i have included the code ive written so far ,you can see im using an array and then just a couple of different changes with delays in between so i can see if my code is working .. the leds connected to the shift register are flickering although they do almost seem to be the correct ones that flicker but it might be just coincidence , what am i doing wrong??

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
// Pin Connected to Mreclear pin
const int MReclearPin = 2;

int SRout[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

void setup() {
  // put your setup code here, to run once:
  pinMode(MReclearPin,OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  digitalWrite(MReclearPin,HIGH);
}
// the function i wrote to build the binary string and send it out to the shift regs
void SRoutWrite (){
  for (int ThisByte = 0; ThisByte < 15; ThisByte++){
    registerWrite(ThisByte,SRout[ThisByte]);
    
  }
      
}

void loop() {
// here are just some tests
// it should turn on the first led , then after a second the next and after a second the next 
// while not turning any of them off even for a millisecond

SRout[0] = 1;
SRoutWrite();
delay (1000);

SRout[1] = 1;
SRoutWrite();
delay (1000);

SRout[2] = 1;
SRoutWrite();
delay (1000);

SRout[3] = 1;
SRoutWrite();
delay (1000);


 
  
  
}

// i took this void from the arduino shiftout examples
void registerWrite(int whichPin, int whichState) {
  // the bits you want to send. Use an unsigned int,
  // so you can use all 16 bits:
  unsigned int bitsToSend = 0;    

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

  // break the bits into two bytes, one for 
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = lowByte(bitsToSend);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);

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

Let's see if I can simplify things:

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
// Pin Connected to Mreclear pin
const int MReclearPin = 2;

unsigned int SRout = 0;  // Start with all pins off


void setup() {
  // put your setup code here, to run once:
  pinMode(MReclearPin,OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  digitalWrite(MReclearPin,HIGH);
}

void loop() {
// here are just some tests
// it should turn on the first led , then after a second the next and after a second the next 
// while not turning any of them off even for a millisecond

registerWrite(0, HIGH);
delay (1000);

registerWrite(1, HIGH);
delay (1000);

registerWrite(2, HIGH);
delay (1000);

registerWrite(3, HIGH);
delay (1000);
}

// i took this void from the arduino shiftout examples
void registerWrite(int whichPin, int whichState) 
    {
    unsigned int lastOutput = SRout;  // Save the previous pin states

    bitWrite(SRout, whichpin, whichstate);  //  Set the specified bit to the specified value

    if (SRout != lastOutput)  // If the value has been changed
        {
        // turn off the output so the pins don't light up
        // while you're shifting bits:
        digitalWrite(latchPin, LOW);

        shiftout(dataPin, clockPin, MSBFIRST, highbyte(SRout));
        shiftout(dataPin, clockPin, MSBFIRST, lowbyte(SRout));

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

[/quote]

Thanks very much!!! code works great now just as i intended ! and you managed to simplify it quite a lot too

it seems quite often there is an easier way of doing things .

thanks again

incase anyone is interested i am creating an arduino based controller board for my american style fridge freezer which includes onewire temp sensors in both compartments , ice machine control and chilled water dispensor and an lcd 4 x20 user interface on the front all using one arduino duemilanove with shiftout and shiftin registers to get enough IO