I'm having a problem controlling 8 LEDs that are hooked up to an 74HC595 Serial to Parallel IC.
First problem:
For demonstration purposes, I am using a for loop to shift though each of the 8 LEDs back and forth. For some reason, the second for loop doesn't do what its supposed to do and shift the LEDs the opposite direction. No matter what I change i.e. LSBFIRST, changing << to >> etc. it just seems to want to start from Q0 and end at Q7.
void loop() {
for (int i=0; i<8; i++) {
shiftOut(dataPin, clockPin, MSBFIRST, B00000001 << i);
digitalWrite(latchPin, HIGH);
delay(125); // 125*8 is 1 second
digitalWrite(latchPin, LOW);
}
for (int i=0; i<8; i++) {
shiftOut(dataPin, clockPin, MSBFIRST, B10000000 >> i);
digitalWrite(latchPin, HIGH);
delay(125); // 125*8 is 1 second
digitalWrite(latchPin, LOW);
}
}
Second problem:
Again for demonstration purposes, I tried to switch the first 4 LEDs on followed by the last 4 LEDs like so:
If I was going to hardwire a 74HC595 with a lot of LEDs, would it be best to implement a tactile button for the "master reset" and the "output enable" pins? If its yes for the both, why the "output enable" also?
daz1761:
If I was going to hardwire a 74HC595 with a lot of LEDs, would it be best to implement a tactile button for the "master reset" and the "output enable" pins? If its yes for the both, why the "output enable" also?
I'm not sure why any of that would be necessary.
You could call a function in setup() to knock out all 0's to clear it out (and just use the Reset button from there.)
I'm not sure why any of that would be necessary.
You could call a function in setup() to knock out all 0's to clear it out (and just use the Reset button from there.)
OE should connect to Gnd to be always on, or to PWM for brightness/fade control.
Connecting to 5V will disable the outputs.
That's interesting - I did previously mention how I could incorporate PWM and I came across ElcoJacob's PWM library. Tbh, I don't need individual LEDs changing brightness. I just would like all 8 LED's of the one IC to fade in - hold for so many seconds - then fade out.
I've not got an Arduino to hand atm, but would something like this work if I connect the output enable (OE) to a PWM pin on the Arduino:
const int output_enable_pin = 6;
void loop() {
// fade in example?
for (int i=255; i>0; i--) {
analogWrite(output_enable_pin, i);
delay(10);
}
// keep LOW
// fade out..
}
Just tried my code out and it works fine. I have the first 4 LEDs fade in (0b00001111), then the last 4 fade in (0b11110000).
The only strange thing I noticed was when I pulled the jumper out that took the Output Enable (OE) straight to ground while the Arduino was on, I expected the all of the LEDs to power down until I put the pin into a PWM pin and re-programmed the Arduino.
Was this because the OE was in a floating state (neither gnd or high)?