I'm trying to implement an Arkanoid game on a 16x16 RGB matrix (the library is Adafruit_NeoMatrix). The blocks are 2x2 squares, and there are 3 rows with 8 blocks in each. The current state of the game (which of the blocks are still present) is stored in a 8x3 int array called blocks. 0 means no block, and 1–3 mean a block with a specific color (the color is randomly selected at setup).

Here's the function I use for rendering the blocks (SIZE_X is 16, BLOCKS_HEIGHT is 3, and matrix is the Adafruit_NeoMatrix instance used to control the matrix):

int blocks[BLOCKS_HEIGHT][SIZE_X / 2] = {
  { 1, 1, 1, 1, 1, 1, 1, 1 },
  { 2, 2, 2, 2, 2, 2, 2, 2 },
  { 3, 3, 3, 3, 3, 3, 3, 3 }

void renderBlocks() {

  for (int i = 0; i < SIZE_X / 2; i++) {
    for (int j = 0; j < BLOCKS_HEIGHT; j++) {
      if (blocks[j][i] > 0) {
        uint16_t color;
        switch (blocks[j][i]) {
          case 1:
            color = matrix.Color(200, 0, 0);
          case 2:
            color = matrix.Color(0, 200, 0);
          case 3:
            color = matrix.Color(0, 0, 200);

        matrix.drawPixel(i * 2, j * 2, color);
        matrix.drawPixel(i * 2 + 1, j * 2, color);
        matrix.drawPixel(i * 2, j * 2 + 1, color);
        matrix.drawPixel(i * 2 + 1, j * 2 + 1, color);


In a real game, it would be called each time the ball knocks out a block, but as for now it's all I have implemented, because the following issue is stopping me. (Currently it's called one time per second in the loop.)

Here is what appears in the serial monitor:

Serial monitor

When I plug in the Arduino, it waits for some time, then shows this on the matrix, prints "rend" and disconnects. (Looks like it doesn't finish executing Serial.println("renderBlocks") in the beginning of my function.) Please note that the blocks are displayed in the wrong order: green, then red, then blue, although the hardcoded array means red, green, blue. Also please note that the blue blocks blink (it's more noticeable than on the video). What I'm asking for is an explanation of all those weird things.

The Arduino doesn't seem to be bricked (everything else I load into it works). The matrix works correctly, too (nothing strange happens in other sketches working with it).

Below is the loop:

void loop() {
  if (millis() - lastRenderTime >= 1000) {
    lastRenderTime = millis();

I cannot use delay because in a real game I will have to listen to the control buttons. And I didn't forget to do Serial.begin(9600) at setup.

EDIT: Arduino doesn't switch off completely (the power LED is on), it just disconnects.

EDIT #2: lastRenderTime is unsigned long.

  • 1
    I think your power supply is not sufficient for your whole setup.
    – tepalia
    Commented Jun 9 at 15:06
  • @tepalia The power supply is my computer, and that's enough for Arduino + matrix, as other sketches that deal with the matrix work.
    – SNBS
    Commented Jun 9 at 15:09
  • what data type is lastRenderTime?
    – Juraj
    Commented Jun 9 at 15:39
  • 1
    please do not post a picture of text ... post the text instead ... you copied and pasted the code, do the same with the serial monitor
    – jsotola
    Commented Jun 9 at 17:19
  • 1
    it makes no difference how much text there is ... some people use screen readers, and they cannot read text in a picture
    – jsotola
    Commented Jun 9 at 17:44

1 Answer 1


Unless you post a schematic or picture of the hardware setup, I assume that the power from the led matrix is drawn from the arduino or the USB port. Almost always an arduino resets in the middle of an operation like that, it is because of power drop or short circuit. If you have a scope you can monitor the input voltage of the Arduino. I suspect that the power drops too much. Try to power the matrix from its own power supply and connect the GND of the power supply and the usb/arduino together to create a common ground.

  • Yes, I've already resolved the issue this way.
    – SNBS
    Commented Jun 13 at 12:04

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