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
    }
}
5
  • 2
    it is about displaying text on 8x8 led matrix using arduino/ Commented Jul 5, 2021 at 16:04
  • its not really about loops in c++, what would be helpful is more detail about the hardware, platform, and the libraries in use. Data-types and libraries seem to be the main issues here.
    – j0h
    Commented Jul 6, 2021 at 1:49
  • 1
    @jsotola, it is an Arduino question. it is about the use of Arduino's Print.print(num, HEX) function which doesn't have a version for uint64_t type so it must be replaced with at least two prints and the leading 0 must by handled
    – Juraj
    Commented Jul 6, 2021 at 5:07
  • @Juraj i am probably missing something then ... i see no Serial.print code in OP's listing ... deleted my comments
    – jsotola
    Commented Jul 6, 2021 at 5:44
  • @jsotola, sorry, some display libraries implement base class Print and the Answer by j0h confused me to think it is the case in this Question
    – Juraj
    Commented Jul 6, 2021 at 7:49

1 Answer 1

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.

1
  • welp, I see where I borked this code, but im tired and huingry, and gotta go home. But I still think this will put you close to where you want to be
    – j0h
    Commented Jul 5, 2021 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.