In the previous article, we used the LED Matrix on the Arduino Uno Q to produce 'falling' dots that resemble rain. This is basic code in Python to create the 'rain' on the LED Matrix.
Now, we are going to get a little more advanced.
Back in the DOS days, there were programs that would act more like screensavers, and some were very interesting to watch. Specifically, the one named 'Plasma' or sometimes 'Ooze'. The basis is the use of 256 colors, which cycle through the colors and start over again. The screen is an even change from one color to the next and it flows. We can see in Figure 1, a sample of a stationary initialization screen.
FIGURE 1
We can try to do the same thing with the LED Matrix, but it will not quite look the same since it has only one color. It will oscillate through the LED intensities and change the LED Matrix.
Also, once we show that part, we can look at using similar code to create 'moving' images.
For the basic setup, you need to look at the previous article on 'Rain'. So we can get straight into the app's code.
Program Code
After you create a new app, give it a name like 'Plasma'. After you create the app, you need to delete the C++ code under 'sketch/sketch.ino' and the Python code in 'python/main.py'.
For the C++ code, you need to place the following into 'sketch/sketch.ino':
Code:
// SPDX-FileCopyrightText: Copyright (C) Arduino s.r.l. and/or its affiliated companies
// SPDX-License-Identifier: MPL-2.0
#include <Arduino_RouterBridge.h>
#include <Arduino_LED_Matrix.h>
#include <vector>
Arduino_LED_Matrix matrix;
const uint8_t FRAME_ROWS = 8; // Rows
const uint8_t FRAME_COLS = 13; // Columns
const uint8_t FRAME_SIZE = FRAME_ROWS * FRAME_COLS; // Total number of pixels in frame
uint8_t frame[FRAME_SIZE] = {0}; // Global frame buffer initialized to zeros (empty frame)
void setup() {
matrix.begin();
matrix.setGrayscaleBits(3); // Set the number of bits for brightness levels to 3 (0-7 values)
matrix.clear();
Bridge.begin();
Bridge.provide("draw", draw);
}
void loop() {
matrix.draw(frame); // Draw the current frame on the display
delay(10);
}
void draw(std::vector<uint8_t> newFrame) {
size_t len = min(newFrame.size(), (size_t)FRAME_SIZE);
memcpy(frame, newFrame.data(), len);
}This is the same C++ code that was in the 'Rain' program, so I will not go over it again.
Now, we need the Python code:
Code:
def showLED():
frame = Frame(matrix)
frame_bytes = frame.to_board_bytes()
Bridge.call("draw", frame_bytes)
from arduino.app_utils import App, Bridge, Frame
import numpy as np
import time
import random
import sys
matrix = np.array(
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
dtype=np.int32,
)
change = np.array(
[
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
dtype=np.int32,
)
showLED()
random.seed()
matrix[0][0] = random.randint(0, 7)
for i in range(1,8):
b = matrix[i-1][0]
b1 = random.randint(1, 100)
if (b1 <= 50):
b2 = b - 1
matrix[i][0] = b2
if (b2 < 0):
change[i][0] = 1
matrix[i][0] = 1
if (b1 > 50):
b2 = b + 1
matrix[i][0] = b2
if (b2 > 7):
change[i][0] = -1
matrix[i][0] = 6
for i in range(1,13):
b = matrix[0][i-1]
b1 = random.randint(1, 100)
if (b1 <= 50):
b2 = b - 1
matrix[0][i] = b2
if (b2 < 0):
change[0][i] = 1
matrix[0][i] = 1
if (b1 > 50):
b2 = b + 1
matrix[0][i] = b2
if (b2 > 7):
change[0][i] = -1
matrix[0][i] = 6
for j in range (1,13):
for i in range (1,8):
b = matrix[i-1][j]
b1 = matrix[i][j-1]
b2 = random.randint(1, 100)
b3 = int((b + b1) / 2)
if (b2 <= 50):
matrix[i][j] = b3 -1
if matrix[i][j] < 0:
matrix[i][j] = 1
change[i][j] = 1
if (b2 > 50):
matrix[i][j] = b3 + 1
if matrix[i][j] > 7:
matrix[i][j] = 6
change[i][j] = -1
showLED()
try:
while True:
for i in range(8):
for j in range(13):
matrix[i][j] = matrix[i][j] + change[i][j]
if matrix[i][j] < 0:
matrix[i][j] = 1
change[i][j] = 1
if matrix[i][j] > 7:
matrix[i][j] = 6
change[i][j] = -1
showLED()
time.sleep(.25)
except KeyboardInterrupt():
matrix.fill(0)
showLED()
sys.exit(0)Some of this we went over in 'Rain', but I will still go over most of it.
We start off with a function with the name of 'showLED'. The function takes the values in the NumPy array 'matrix' and passes them to the microcontroller to process the values and place them in the LED Matrix.
The 'matrix' array is an array that is 8 by 13, just like the LED Matrix. The values are from 0 to 7. A value of 0 means it turns off the LED, while a value of 7 turns on the LED to its full brightness. All the numbers in between are of varying intensity.
Next, we import the libraries we need for the program.
The next two commands create a two-dimensional NumPy array. One is 'matrix', which we manipulate to send to the microprocessor. The second is 'change'. The array is for holding the increment or decrement that is for the arithmetic when we change the 'matrix' for the ability to cause effects that move. We will look into this more after describing this app to cover other effects.
The 'matrix' array is empty, so we can then call the ShowLED function to clear the matrix.
Since we are using random numbers, we need to randomize the seeds that we use to generate numbers. This way the code does not always generate the same values. To randomize the generator, we use the command 'random.seed()'.
We then assign the LED at the row and column ([0][0]) a random number between 0 and 7. This is a base starting point for the intensity of the first LED.
The following code is for the rest of the first row:
Code:
for i in range(1,8):
b = matrix[i-1][0]
b1 = random.randint(1, 100)
if (b1 <= 50):
b2 = b - 1
matrix[i][0] = b2
if (b2 < 0):
change[i][0] = 1
matrix[i][0] = 1
if (b1 > 50):
b2 = b + 1
matrix[i][0] = b2
if (b2 > 7):
change[i][0] = -1
matrix[i][0] = 6The rest of the row is positions 1 through 7 in the first row, which is row 0.
We set the variable 'b' equal to the value in the specified row, to the left of the current row, and column 0. We then assign a random value to 'b1', which is between 1 and 100.
If the random value in 'b1' is less than or equal to 50, we subtract one from the previous value in 'b' and set this to the variable in 'b2'. We then place the value in 'b2' into the current position in 'matrix'. If 'b2' is less than 0, an invalid amount, we change it to 1 and set the 'change' value to a positive 1. It must be positive since we will count up now and not down.
If the random value is greater than 50, then we will increase the value in the previous array element. We must then check if the value is over 7. If the value is over 7, we change it to 6 and also set the 'change' value for the position to '-1' since we will count down now.
This will set the first row's values. Now, we need to do the same for the first column, which is the next section of code.
The next section of code will fill in the rest using the same methods. The code covers rows 1 through 7 and columns 1 through 12:
Code:
for j in range (1,13):
for i in range (1,8):
b = matrix[i-1][j]
b1 = matrix[i][j-1]
b2 = random.randint(1, 100)
b3 = int((b + b1) / 2)
if (b2 <= 50):
matrix[i][j] = b3 -1
if matrix[i][j] < 0:
matrix[i][j] = 1
change[i][j] = 1
if (b2 > 50):
matrix[i][j] = b3 + 1
if matrix[i][j] > 7:
matrix[i][j] = 6
change[i][j] = -1We now have a randomized configuration of intensities for the LED Matrix. The 'showLED' is then used to display the variances in the LEDs.
For this to work and show a change in the LED Matrix, we need to change the entries and call the function 'showLED'. The code is:
Code:
try:
while True:
for i in range(8):
for j in range(13):
matrix[i][j] = matrix[i][j] + change[i][j]
if matrix[i][j] < 0:
matrix[i][j] = 1
change[i][j] = 1
if matrix[i][j] > 7:
matrix[i][j] = 6
change[i][j] = -1
showLED()
time.sleep(.25)The code goes through all the rows and columns. It finds the value in 'matrix' and adds the value in the corresponding 'change' element. It uses the result to check again if the value is less than 0 or greater than 7. If it is out of range, it corrects it and the 'change' value. Once we configure the entire array, we run the function 'showLED' again, and a short timer sets a delay so things don't move too fast.
This is the program, and the LED Matrix can be seen in Video 1.
VIDEO 1
Using the Change Array
With a little modification, you can set the elements in the 'change' array to change the LEDs that you want to change. For those that you do not want to change, just leave the entries as zero.
Next, you need to change a little code:
Code:
if change[i][j] != 0:We can place this at the beginning of the code for modifying and checking the 'matrix' values. This way, the app processes only the non-zero elements in 'change', which are the same elements in 'matrix'. In this manner, only specific LEDs will change.
Let's look at an example:
Code:
matrix = np.array(
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 5, 6, 6, 6, 0, 0, 0, 2, 3, 3, 0, 0],
[5, 0, 0, 0, 0, 7, 0, 2, 0, 0, 0, 4, 0],
[5, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 5],
[0, 4, 0, 0, 0, 2, 0, 7, 0, 0, 0, 0, 5],
[0, 0, 4, 3, 3, 0, 0, 0, 7, 7, 6, 6, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
dtype=np.int32,
)
change = np.array(
[
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0],
[1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
[0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1],
[0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
],
dtype=np.int32,
)This is the setup of the arrays. We only need part of the code from the first example, since we are configuring the screen in the array setup. The code is:
Code:
showLED()
try:
while True:
for i in range(8):
for j in range(13):
matrix[i][j] = matrix[i][j] + change[i][j]
if change[i][j] != 0:
if matrix[i][j] < 1:
matrix[i][j] = 2
change[i][j] = 1
if matrix[i][j] > 7:
matrix[i][j] = 6
change[i][j] = -1
showLED()
time.sleep(.20)
except KeyboardInterrupt():
matrix.fill(0)
showLED()
sys.exit(0)The video from this example is shown in Video 2.
VIDEO 2
NOTE:
You may need to replace the tabs in the above code with four spaces for each tab.Conclusion
This should give you a basis for how these methods can help create different animation.
This is definitely something to experiment with and have fun.
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | Arduino Uno Q - LED Matrix - Rain | 0 | 7.66 | 08-09-2026 |
| 2 | SwapLite - swaplite.cc | 0 | 10 | 27-09-2026 |
| 3 | Как писать промпты для нейросети: метод с отладчиком | 0 | 7.66 | 25-09-2026 |
| 4 | Queen | 0 | 10 | 29-09-2026 |
| 5 | Lendex - lendex.me | 0 | 10 | 27-09-2026 |
| 6 | Mitrola - Mitrola.net (mitrola.com) | 0 | 10 | 27-09-2026 |
| 7 | Python Series Part 25: Canvas Widget - Part 2 | 0 | 27.65 | 04-09-2026 |
| 8 | Штекера, разъемы | 0 | 10 | 28-09-2026 |
| 9 | 0 | 0 | 01-01-1970 | |
| 10 | 0 | 0 | 01-01-1970 |