I am trying to implement an animation shifting function, that will allow me to shift all (LAYERS*BYTES) LEDS by 32 bits with an overlap. I only could do it with byte shifting, but that is not what I need.
To better understnad the idea, the image is provided below:
I drew it out where C is a carry bit that is moved to the start of the following byte and the last element of 4 bytes is assigned to the first element of the first byte.
There might be a better way to implement this. I appreciate for any help in advance.
Additional information:
void Shift_Right_Byte(void){
for (int row = 0; row < LAYERS; row++) {
for (int col = 0; col < BYTES; col++) {
LED_Buffer[row][col] = LED_Buffer[row][(col + 1) % BYTES];
}
}
delay(1000);
}
New function:
void layer_rotate_right(void)
{
for (int row = 0; row < LAYERS; row++) {
unsigned char carry = LED_Buffer[row][BYTES - 1] << 7 ;
for( int i = 0; i < BYTES; i++ )
{
unsigned char next_carry = LED_Buffer[row][i] << 7 ;
LED_Buffer[row][i] = (LED_Buffer[row][i] >> 1) | carry ;
carry = next_carry ;
}
}
}
uint32_t*
using a a shift | masked_shift (sometimes known as a "barrel roll" or "circular shift"). The bit patterns of the device are important (and may require a 'mix' instead of a shift on, eg, Big Endian). – user2864740