Hi JoopC,
Simple answer is that, if all you have is the 74HC595, you can't know the output state of the pins until you have set them.
This can be a real problem at power on / reset.
There are some strategies to get the values:
- You could run a wire back to the Netduino so you can read the state - but that defeats the purpose of using the shift register to get more I/Os!
- You could add an input shift register (74HC165) to read all the outputs of the 74HC595 and convert them back into a serial message that you can read on the SPI bus. Again this is a bit wasteful unless there are other inputs you needed to sample also, and there is the delay of reading the shift register before you get your answer.
- Better would be to create a persistent variable that holds the last word you wrote to the shift register, and add some methods to read the word in what ever format you need. Ideally wrap it in a class to look after everything for you once you understand how to write each bit of the code.
There is still the power on / reset problem.
One strategy here is to use the enable signal of the 74HC595 to set the outputs to high impedance (e.g. "OFF") at program start, and use pullup or pulldown resistors to set each output to a sensible initial level for your circuit. Once you have written the initial state into the 74HC595, you then enable the outputs of the shift register.
Lots to think about, remember its supposed to be fun - Paul