Error - Lighting Led with 74HC595

Asked

Viewed 124 times

1

Hello

I’m trying to light the led 1 that is in the pin 1 of 74HC595 and the rest are erased and then erase the led 1 and light only the led 2 that is in the pin 2 of 74HC595, but the problem I’m having is that all the leds stay lit together, which may be wrong ?

#define latchPin 5
#define clockPin 6
#define dataPin 4

void setup() {

pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

digitalWrite(latchPin, HIGH);
shiftOut(dataPin, clockPin, LSBFIRST, 0b10000000);
digitalWrite(latchPin, LOW);
delay(1000);
digitalWrite(latchPin, HIGH);
shiftOut(dataPin, clockPin, LSBFIRST, 0b01000000);
digitalWrite(latchPin, LOW);
delay(1000);

}

Thank you

  • This depends a lot on how the 74HC595 is connected to the Arduino. Being a serial/parallel converter, it is difficult to answer without the diagram. Questions about hardware are not in the scope of the site, but in case maybe the diagram serves to analyze the software part.

  • An attempt would be to use a digitalWrite(clockPin, LOW) before the shiftOut, in case the 74hC595 clock operates on the signal rise.

  • Another thing, depending on how you turned on the 74HC595, the correct sequence would be latchPin -> LOW, shiftOut and then latchPin -> HIGH, which would be the inverse of its code. However, without the diagram, it is difficult to say.

1 answer

0


Try to use a delay between the high ones in the loop is best

#define latchPin 5
#define clockPin 6
#define dataPin 4
#define tempoAtualiza 1
void setup() {

pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

digitalWrite(latchPin, HIGH);
delay(tempoAtualiza * 1000);
digitalWrite(latchPin, LOW);
delay(tempoAtualiza * 1000);

digitalWrite(latchPin, HIGH);
delay(tempoAtualiza * 1000);
digitalWrite(latchPin, LOW);
delay(tempoAtualiza * 1000);

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.