First of all, I know that there are many tutorials about how to program 74HC595 shift register. Also Arduino provides the code with some pre-made functions. But I really want to get to know 74HC595 and program it by myself. First I connected all the inputs to push buttons and everything was working as it should be, but after that, I just connected the inputs of the chip to an Arduino. The target is to just write the bits that are in the data_bits to LEDs, but instead, every LED just lights up.
Here's the code:
#define data 11
#define latch 8
#define clock 12
boolean data_bits[8] = {LOW, HIGH, LOW, HIGH, LOW, HIGH, HIGH, HIGH};
void update_data(){
digitalWrite(latch, LOW);
for(int i = 7; i >= 0; i--){
digitalWrite(clock, LOW);
digitalWrite(data, data_bits[i]);
digitalWrite(clock, HIGH);
}
digitalWrite(latch, HIGH);
}
void setup(){
pinMode(data, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(clock, OUTPUT);
}
void loop(){
update_data();
}