Step 6: Load the Matrix Scanning Code

Now, load the Arduino sketch for scanning the matrix. I have provided the Arduino source code. Once you have loaded it, you should see a flash of light sweeping the matrix every few seconds.

If you bring the phototransistor close to the matrix, you should see that LEDs near the phototransisor are illuminated.

Try moving the phototransistor further and closer to the matrix to see how it behaves like a flashlight. If you place an object on the matrix and hold the phototransistor above it, you should be able to capture a “shadow” of the object!

There are a few parameters you can tweek in the code:

static constexpr uint8_t  READINGS_PER_PIXELS = 1;
static constexpr uint8_t  THRESHOLD           = 15;
static constexpr bool     INVERT              = false;
static constexpr bool     CLEAR               = true;

If the detection isn’t working well, you can try increasing READING_PER_PIXEL and THRESHOLD. Set CLEAR to false to get a paintbrush like effect where each new scan adds more “paint” to the canvas. Set INVERT to true for a negative effect, where the matrix is normally lit, but the phototransistor darkens what it can “see”.