Stuck on NeoPixel 8x8 Matrix code

Hey everyone!

I have spent about 4-6 hours looking at this code, and different code examples with no success.

Basically, I'm trying to do a "Tetris" animation on the NeoPixel 8x8 Matrix using the GFX, NeoMatrix, and NeoPixel libraries. To cut down on memory usage on the Arduino, I am trying to create as few functions as possible. Due to that fact, I am trying to use one animation function to make a red 4x4 box move to the bottom of the matrix, then calling that same function, I make a blue box drop on the side of the red box. Unfortunately, when I call the function again with a different color value, it doesn't work. It just hangs there. I narrowed it down to the code just "floating" at the end of the for() function (by float, I mean that it just waits there, and doesn't do anything i.e. restart). I have been pulling my hair out for the past few hours, trying to figure out why this code won't work! Please have a look at my example code! :sob:

Simply put, I'm trying to make the red box move to the bottom, STOP, then have a blue box come down next to the red box, but while using the same function I used for the red box.

Thanks for your time, and help!
Have a good one! :slight_smile:

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6


Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 6, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);


int delayval = 250; // delay for half a second


uint32_t red = matrix.Color(255, 0, 0);
uint32_t orange = matrix.Color(255, 137, 0);
uint32_t yellow = matrix.Color(255, 255, 0);
uint32_t green = matrix.Color(0, 255, 0);
uint32_t blue = matrix.Color(0, 0, 255);
uint32_t purple = matrix.Color(204, 0, 204);
uint32_t black = matrix.Color(0, 0, 0);
uint32_t white = matrix.Color(255, 255, 255);



void setup() {
  matrix.begin();
  matrix.setBrightness(16);
  matrix.show();
}




void loop() {

  fillRect(0, 0, 4, 4, red);
  fillRect(0, 0, 4, 4, blue);
  matrix.show();

}

void fillRect(uint16_t x, uint16_t y0, uint16_t w, uint16_t h, uint16_t color) {
  int y = -3;//x-axis starting point.


  for (;; y++) {
    matrix.fillScreen(black); //This goes before to "wipe" the following rectangle pixels.
    matrix.fillRect(x, y, w, h, color);
    y  = constrain (y, -3, 3);
    matrix.show();
    delay(delayval);
    if (y >= 3) {
      y = 3;
    }
  }
}

Look at this information in the learning area of the site. It describes how a for loop works. Examine your for statement. How will it terminate?