1

I have an array of 64-bit integers to display on an 8x8 led matrix

const int LEN1 = sizeof(Hours);
const uint64_t Hours[] = {
  0x00043c3c3c3c3c00,
  0x000c3c3c3c3c3c00,
  0x001c3c3c3c3c3c00,
  0x0000001818000000,
  0x0000001818100000,
  0x0000001818180000,
  0x00000018181c0000,
  0x000000181c1c0000,
  0x0000001c1c1c0000,
  0x0000041c1c1c0000,
  0x00000c1c1c1c0000
};

and here I have a loop to display it:

void displayImage(uint64_t image) {
  for (int i = 0; i < 8; i++) {
    byte row = (image >> i * 8) & 0xFF;
    for (int j = 0; j < 8; j++) {
      lc.setLed(0, i, j, bitRead(row, j));
    }
  }
}

but I can't use a loop in this way and I'm not proficient in byte shifting principles too.

can you please explain how the loop above works or help me to write this loop as

const int LEN1 = sizeof(Hours);

void displayImage(Hours[]) { for (int i = 0; i < LEN1; i++) { //display Hours } }

1 Answers1

0

ok, well there are some things I don't know about your code, and hardware, like if the LCD library can handle uint64_t datatypes. I know the Serial.print() function can only handle up to a unit32_t, so I'm using that.

I think your length variable might not be the right length, you might want to add in a check for that in your code. Much of the Arduino code is 8 bit.

void setup() {
Serial.begin(9600);
uint32_t b = 0x0;

const uint64_t Hours[] = { 0x00043c3c3c3c3c00, 0x000c3c3c3c3c3c00, 0x001c3c3c3c3c3c00, 0x0000001818000000, 0x0000001818100000, 0x0000001818180000, 0x00000018181c0000, 0x000000181c1c0000, 0x0000001c1c1c0000, 0x0000041c1c1c0000, 0x00000c1c1c1c0000 };

//const int LEN1 = sizeof(Hours[0]); const int LEN1 = sizeof(Hours)/sizeof(uint64_t); Serial.print("Length: "); Serial.println(LEN1);

for (int i = 0; i < LEN1; i++) { b=Hours[i]>>16; Serial.println(b,HEX); } }

void loop() { }

I think this code will do what you want, at least as I understand it. beware of what data-types your LCD library can handle.

j0h
  • 902
  • 4
  • 13
  • 30