I'm trying to create an animation on an LCD display using custom characters. I don't want to define every single custom character. Some characters are reusable if you simply flip them.
A 8x5 custom character is defined like this:
byte blankChar[8] = {B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000};
To flip that character on the horizontal axis you just need to change the order of the bytes. But to flip it on the vertical axis you would need to reverse the bytes.
What I mean is B00111 should be turned into B11100, or B10000 to B00001. How do I do that?
Manually with bitwise operators. I don't think there's a more graceful way.
end = ((start&0x01)<<7)|((start&0x02)<<5)|((start&0x04)<<3)|((start&0x08)<<1)|((start&0x10)>>1)|((start&0x20)>>3)|((start&0x40)>>5)|((start&0x80)>>7);
or loop through it like
byte end=0;
for (byte x=0;i<8;i++) {
end = end <<1; //push bits already in there over by one
end |= ((start>>i) & 0x01); //shift start x bits to the right, bitwise and with 1. |= is bitwise-or-equals, same idea as += and the like.
}