all outputs high on shift register (74HC595) code

hi guys,

Please help me with the code for shift register (74HC595).

I am trying to get all 8 outputs high to light up leds contantly, I am struggling to understand how the latch, clock and data pin work in the code, please help

cheers

Post your code and schematic and a photo of your circuit.

would this work:

{
for (int h = 0; h < 8; h)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, h);
digitalWrite(latchPin, HIGH);
}
}

i dont think i need the most significant bit first as i am not shifting just setting all outputs to high however,
the ide requires this for the arguement.

what do you guys think/ is there a better way to code this?

cheers

No, just this:

h = 0b11111111; or h = 0xff; or h = 255;

all will result in all 1's at the output. then

digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, h); digitalWrite(latchPin, HIGH); // outputs change on this rising edge

Make sure OE/ is LOW, can be connected to GND, or to a PWM pin and SRCLR is connected to +5. Don't forget 0.1uF cap from VCC pin to GND.

it hasnt worked

code below is as follows:

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

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

void allOn() { digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, 255); digitalWrite(latchPin, HIGH); }

void loop() { digitalRead(modeSwitch); { if (modeSwitch = HIGH) { allOn; } } }

what am i doing wrong

How is modeSwitch wired up? Pulldown resistor to Gnd, close switch to connect to 5V?

Need == here for comparison: if (modeSwitch = HIGH)

Gonna add something to make them all 0 too?

it is a open/close switch. Either on or off.

to set all outputs to low would i have an else statement and just set the latchpin HIGH?

e.g.

{ digitalRead(modeSwitch); { if (modeSwitch == HIGH) { allOn; } { else { digitalWrite(latchPin, HIGH); } } }

No, you'd have an alloff function:

void allOff()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 0);
  digitalWrite(latchPin, HIGH);
}

thanks for your help dude!

Glad to help.