Problem controlling LEDs using 74hc595 shift register

Hi there. I am an experiend programmer but a newbie controlling LEDs with an Arduino. I have the following code:

void runUp()
{ leds = 256;
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister();
delay(tDelay);
};
}

This lights 8 LEDs sequentially, whilst keeping each one on, if you see what I mean.

Having done this, I want the reverse to happen - so they should all be on from the above code and then sequentially go off one at a time. I have written this:

void runDown()
{ leds = 0;
for (int i = 8; i > 0; i–)
{
bitSet(leds, i);
updateShiftRegister();
delay(tDelay);
};
}

but it turns them all off and then lights them up in the reverse order.

I can’t see how to make it do what I want as I fundamentally don’t follow what is happening between the variable led and the bitShift().

Can anyone help me please?

David

Please post your complete program using code tags when you do to prevent the forum software mangling it and to make copying it for examination in an editor easier

At the very least if they all want to be ON to begin with it should set leds to 255, all bits set, see what I mean?

And at the very last, to turn one off you prolly want to clear the corresponding bit, not set it.

Since you only have 8 lamps, 256 is the same as 0 - no bits set in the least significant byte.

Think it through, this is pretty straight ahead you almost have it,

Post all the code and maybe a schematic. There is no clue as to what these alleged leds consist in.

a7