I am writing a function for use in a LED project on a esp32. I am using 2D arrays to store RGB hex codes and calling my gradientFunction to send to a BLE controller, but the number colors of may vary:
...
if (counter == 0) {
uint8_t rgb[4][3] = { {0xff, 0x00, 0x00}, {0xff, 0x11, 0x11}, {0xea, 0x1f, 0x10}, {0xff, 0x00, 0x00} };
gradientFunction(rgb);
Serial.println("Red gradient");
}
}
void gradientFunction(uint8_t rgb[][3]) {
int length = sizeof(rgb) / sizeof(rgb[0]);
Serial.println(length);
for (int i = 0; i < length; i++) {
uint8_t bytes[9] = {0x7b, 0x01 + i, 0x0e, 0xfd, rgb[i][0], rgb[i][1], rgb[i][2], length, 0xbf};
pRemoteCharacteristic->writeValue(bytes, 9);
delay(100);
}
}
However, calculating the number of rows (length) returns 1. Printing sizeof(rgb) returns 4 and sizeof(rgb[0]) returns 3. This results in only 1 color code being transmitted to the BLE controller.
I can't seem to figure where I am going wrong with calculating the number of rows, or am I calling the function incorrectly?