# using array with ShiftOut

Hi,
I'm writing program to control shift register.
I have this array:

int arr[8] = {0, 0, 0, 0, 0, 0, 0, 0};

It's like byte arr = 0b00000000, but i want to use array, because I need indexing and etc.
I want to use it with ShiftOut. How can i do this?

Well build a byte with your 8 individual bits and then shift it out?

There are bit related operations already defined if you don't want to do the bit masking dance yourself

Or go look at the code of shiftOut and do something similar with your array instead of bits

My view though is that you should not deal with an array, just use bytes and use the bit manipulation function above for your indexing purpose. Saves memory...

i want to use array, because I need indexing and etc.

Why not leave it in a byte and access the bits with an index and the bitRead() function ?

thanks for replies,
I looked for bitSet, BitClear and BitRead, but arrays are still better for my application
here is fraction of my code:

``````int buttonState = digitalRead(buttonPin);

int arr[8] = {0, 0, 0, 0, 0, 0, 0, 0};

if (buttonState == HIGH) {
for (int x = 6; x >= 0; x--) {
arr[x] = arr[x+1];
}
arr[0] = 1;
}

else if (buttonState == LOW) {
for (int x = 6; x >= 0; x--) {
arr[x] = arr[x+1];
}
arr[0] = 0;
}
``````

arr[7] .. arr[1] will always remain 0, no matter how long you set the buttonPin to HIGH.

Don't know what this local int array would be good for.

why?
I think it should work.
if you press button 2 times. arr[0] will shift to arr[1] and arr[0] will be set 1. arr[1] and arr[0] both will be 1.

I will try to explain it with another example. if you press button first arr[0] will be set to 1. after this if you don't click button in 0.25 sec arr[0] will shift to arr[1] and arr[0] will be set to 0. after 0.25 sec arr[1] will be shifted to arr[2] and arr[1] will be set 0. by shifting I mean arr = arr[x+1] (for example arr[1] = arr[2]). this will repeat again and again, until button is clicked.