Bitshift operation help...

Hello,

I'm currently working on a project that has a 12 LED array. The LEDs are supposed to light one by one and stay on, and when the array reaches the end, it goes back to zero and repeats. Kind of like a VU meter but only in one direction.

I've got the problem solved with 2 shift registers in a daisy chain configuration, and the code I've solved with an array and a couple math operations. My array has values from B00000000 to B11111111, and there's a loop that cycles it. Since there's 2 shift registers, the math operation simply tells the second one to stay off until the first one reaches the last pattern.

Initially I had thought of using bitshift operations, but I couldn't get my head around how to do it. From what I've seen, a bitshift simply cycles a bit from "left" to "right" on the register. It would go B10000000, B01000000, B00100000, and so forth.

Is there any type of bitshift operation that would work in my case? That would go progressively change the 0's to 1's in the value with each passing cycle?

bit manipulation is the way to go, but you should post your present code.

added:

you may find it easier to do your bit math in a single unsigned int and push it out to the shift registers in two pieces...

something like this example:

void fillTheLeds()// an example filling the LEDs from high byte to low byte.
{
  unsigned int intToPush = 0U;
  for (int i = 0; i < 16; i++)
  {
    unsigned int myInt = (1U << (15 - i));
    intToPush |= myInt;
    updateLeds(intToPush);
    delay(250);
  }
}

void updateLeds(unsigned int value)
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, highByte(value)); 
  shiftOut(dataPin, clockPin, MSBFIRST, lowByte(value));
  digitalWrite(latchPin, HIGH);
}