1

I've used the following code to light 8 yellow leds sequentially but it only runs as it's supposed to be on Proteus. However in my breadboard the 8 leds keeps blinking all together, the resistors used are 220 ohms. Also when i'm trying to change the value of the variable "leds" to be for example 0x0F, it doesn't light, I've read in the Arduino shiftout tutorial that 0.1F capacitor on the latch pin will even the flickers so now I'm really confused.

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

byte leds = 0;

void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}

void loop() 
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(100);
  }
}

void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);

}

enter image description here

  • The delay after "updateShiftRegister" is only 100ms? This means that within a second all LED's get updated. This would make them appear like blinking? Also; did you try the 0.1F capacitor? – Paul Sep 16 at 10:41
  • what does blinking all together mean? – jsotola Sep 16 at 14:41
1

SOLVED! i've tried many solutions to make it work but it just didn't and here are the solutions i tried a) to use 0.1µf or 10µf between VCC and ground pin of the 74hc595 . b) to set the clockPin and dataPin zero before sending data . c) replacing the resistors from 220 ohm to 470 .

however, i connected pin13 of the 74HC595 to an arduino pin and drive it to zero so the 8 output are ready to go then digitalWrite(out_enable_Pin, HIGH) ,send data as shown in the following code then digitalWrite(out_enable_Pin, LOW) again .

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int out_enable_Pin=13;
int resetPin=5;
char leds = 0;

void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  pinMode(out_enable_Pin, OUTPUT);  
  pinMode(resetPin, OUTPUT);  
}


void loop() 
{
  digitalWrite(out_enable_Pin, LOW);  
  digitalWrite(resetPin, HIGH);

  for (int i = 0; i <255; i++)
  {
    leds=i;
    updateShiftRegister();
    delay(1000);
  }
}

void updateShiftRegister()
{
    digitalWrite(out_enable_Pin, HIGH);
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, leds);
   digitalWrite(out_enable_Pin, LOW);
   digitalWrite(latchPin, HIGH);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.