Can I get the output state after I set it on/off on 74HC595? (How can I do that?)
I want to read the status later to tell which output on/off.
Shift Register 74hc595 state status
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Shift Register 74hc595 state status
Officially the '595 is just a shift register. There's no 'read' command that will tell you the status per se, but there is an output pin connected to the oldest bit in the register. Officially, it's there so you can daisy-chain one '595 after another, creating a storage register as wide as you want.
You *can* use the daisy-chain pin to do a destructive read on the shift register though.. just read the pin and send the clock HIGH and LOW for each bit you want to read. That bascially shifts the entire contents of the register out through the daisy-chain pin.
You can work around the destructive read by writing each bit back to the register's input as you read it:
The code is untested, but the general idea is there. You just cycle the bits around the register once and copy them as they go past. The final HIGH-LOW pulse on the DISPLAY line shifts the contents of the internal register to the output pins so the pins are in sync with the contents of the register.
You *can* use the daisy-chain pin to do a destructive read on the shift register though.. just read the pin and send the clock HIGH and LOW for each bit you want to read. That bascially shifts the entire contents of the register out through the daisy-chain pin.
You can work around the destructive read by writing each bit back to the register's input as you read it:
Code: Select all
#define READ_PIN 1 // these will depend
#define CLOCK 2 // on how you connect
#define DATA 3 // the pins to your
#define DISPLAY 4 // device
int read = 0;
for (int i=0 ; i < 8 ; i++) {
read <<= 1;
read += digitalRead( READ_PIN );
digitalWrite( DATA, read & 1 );
digitalWrite( CLOCK, HIGH );
digitalWrite( CLOCK, LOW );
}
digitalWrite( DISPLAY, HIGH );
digitalWrite( DISPLAY, LOW );
-
- Posts: 466
- Joined: Thu Aug 30, 2012 1:34 am
Re: Shift Register 74hc595 state status
wouldn't it be simpler to retain the data after you've written it to the 595?
Please be positive and constructive with your questions and comments.