I need to declare the 32x8 table where each cell would represent a pixel on the led matrix.
I could define it as byte my_array[32] [8]
But this actually ocupies 8 times more space then I actually need.
I could do it like this int my array [2] [8]
That gives me 2x 16 bit in each row.
But then I am not that proficient with accessing the bits in those integers.
How would you write a command to display all bits to Serial monitor in the loop as an example
for (int i=0,i<32,i++){
for (int j=0, i<8,j++){
(print corresponding bit to serial monitor)
}
}
Or maybe there is a better way to tacke that problem
Thanks. I am trying to figure out how this would work .
I the example I gave how would the command look to display the bit. As those commands refer to individual bytes not to a string of 32 bits right?
uint8_t framebuffer[32] = // 32 columns x 8 lines black or white pixels
{
0x00, 0xFF, 0x08, 0x08, 0x08, 0xFF, 0x00, 0xFF,
0x89, 0x89, 0x81, 0x81, 0x00, 0xFF, 0x80, 0x80,
0x80, 0x80, 0x00, 0xFF, 0x80, 0x80, 0x80, 0x80,
0x00, 0xFF, 0x81, 0x81, 0x81, 0xFF, 0x00, 0xBF,
};
enum color_t : uint8_t {black, white};
void setPixel(uint8_t c, uint8_t l, color_t color) { // 0 <= c < 32 and 0 <= l < 8
switch (color) {
case black: // write a 0 in the corresponding bit
bitSet(framebuffer[c], l); // https://www.arduino.cc/reference/tr/language/functions/bits-and-bytes/bitset/
break;
case white: // write a 1 in the corresponding bit
bitClear(framebuffer[c], l); // https://www.arduino.cc/reference/tr/language/functions/bits-and-bytes/bitclear/
break;
}
}
color_t readPixel(uint8_t c, uint8_t l) { // 0 <= c < 32 and 0 <= l < 8
return (bitRead(framebuffer[c], l) == 1) ? white : black;
}
void printScreen() {
Serial.println("------------------------------------");
for (uint8_t l = 0; l < 8; l++) {
Serial.print("| ");
for (uint8_t c = 0; c < 32; c++) {
Serial.write(readPixel(c, l) == white ? '*' : ' ');
}
Serial.println(" |");
}
Serial.println("-----------------------------------\n");
}
void setup() {
Serial.begin(115200);
printScreen(); // will show our initial Hello pattern
// remove the '!' at the end
for (uint8_t l = 0; l < 8; l++) setPixel(31, l, white);
printScreen();
// clear up the screen (pixel by pixel)
for (uint8_t l = 0; l < 8; l++)
for (uint8_t c = 0; c < 32; c++)
setPixel(c, l, white);
printScreen();
// fill up the screen (pixel by pixel)
for (uint8_t l = 0; l < 8; l++)
for (uint8_t c = 0; c < 32; c++)
setPixel(c, l, black);
printScreen();
}
void loop() {}