Shift in and out work separately but not together

Hello,
we are working on our bachelor project and we have a problem with the shift registers.
We have 8 reed-switches at shift in and LEDs at shift out. Separately in and out work fine but when we try to use them together the lamps don't work, although the input is correct.
Would be nice if someone could help us.
We used: ShiftIN HEF4021BP ; ShiftOUT M74HC595B1
here is our code..

//Pins fuer den shiftIn
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

//Pins fuer den ShiftOut
const int latchPin2 = 13;
const int clockPin2 = 12;
const int dataPin2 = 11;

int reedOn = 0;

byte switchVar1 = 72; //01001000

int test[8]= {0};

void setup() {
//start serial
Serial.begin(9600);

//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);

pinMode(latchPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);

}

boolean leds = false;

void loop() {

reedOn = 0;
//Pulse the latch pin:
//set it to 1 to collect parallel data
digitalWrite(latchPin,1);
//set it to 1 to collect parallel data, wait
delayMicroseconds(20);
//set it to 0 to transmit data serially
digitalWrite(latchPin,0);

//while the shift register is in serial mode
//collect each shift register into a byte
//the register attached to the chip comes in first
switchVar1 = shiftIn(dataPin, clockPin);
Serial.print("Schalter-Byte: ");
Serial.println(switchVar1, BIN);

for(int i=0; i<8; i++){
if(test*==1){*

  • reedOn = i;*

  • }*

  • }*

  • Serial.print("reedOn: ");*

  • Serial.println(reedOn);*

  • Serial.println("-------------------");*

  • for (int thisLed = 0; thisLed < 8; thisLed++) {*

  • // write data to the shift registers: *

  • Serial.print(thisLed);*

  • Serial.println(reedOn);*

  • if (thisLed == reedOn) {*

  • Serial.print("LED an: ");*

  • Serial.println(thisLed);*

  • registerWrite(thisLed, HIGH);*

  • delay(1000);*

  • }else{*

  • registerWrite(thisLed, LOW);*

  • }*

  • delay(250);*

  • }*

  • Serial.println("-------------------");*

  • delay(500);*
    }
    //------------------------------------------------end main loop
    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 = bitsToSend;*

  • //byte registerTwo = lowByte(bitsToSend);*

  • Serial.println("-------------------");*

  • Serial.print("bitsToSend: ");*

  • Serial.println(bitsToSend, BIN);*

  • Serial.println("-------------------");*

  • // 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);*
    }
    byte shiftIn(int myDataPin, int myClockPin) {

  • int i;*

  • int temp = 0;*

  • int pinState;*

  • byte myDataIn = 0;*

  • pinMode(myClockPin, OUTPUT);*

  • pinMode(myDataPin, INPUT);*

  • for (i=7; i>=0; i--)*

  • {*

  • digitalWrite(myClockPin, 0);*

  • delayMicroseconds(0.2);*

  • temp = digitalRead(myDataPin);*

  • if (temp) {*

  • pinState = 1;*

  • //set the bit to 0 no matter what*

  • myDataIn = myDataIn | (1 << i);*
    _ test = 1;_
    * }*
    * else {*
    * //turn it off -- only necessary for debuging*
    * //print statement since myDataIn starts as 0*
    * pinState = 0;*
    _ test = 0;
    * }
    //Debuging print statements*
    * //Serial.print(pinState);
    //Serial.print(" ");
    //Serial.println (dataIn, BIN);
    digitalWrite(myClockPin, 1);
    }
    //debuging print statements whitespace*
    * //Serial.println();
    //Serial.println(myDataIn, BIN);
    return myDataIn;
    }*_

I can tell you didn't read the "How to use this forum - please read. " post at the top before posting...

I don´t understand your problem
I think this question is suitable for "LED´s and Multiplexing, Controlling lots of inputs and outputs"

Fungus wants you to post your code between the hash tags that appear on the message text box if you select the hash tag at the top of the text box third from the right just above the smilies 8)