I am trying to program two LED panels so that by pressing a button, you turn on the first panel and show an arrow to the left and pressing a 2 you turn on panel 2 showing an arrow to the right.
I have already created a program that works with only one LED panel but I don't understand how to adapt it to make it work also by attaching the second panel.
If anyone can help me I would be very grateful.
thanks.
attached I put the code that I managed to do so far and also how I connected the panels.
This is how i connected the panels to arduino Mega:
Panel 1:
GND
OE 9
LAT 10
CLK 11
D A3
C A2
B A1
A A0
GND
B2 29
G2 28
R2 27
GND
B1 26
G1 25
R1 24
Panel 2:
GND
OE 9
LAT 10
CLK 11
D A3
C A2
B A1
A A0
GND
B2 35
G2 34
R2 33
GND
B1 34
G1 32
R1 30
This is the code that i'm using for now:
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>
// Definizioni hardware del pannello LED
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
// Dimensioni del pannello LED
#define PANEL_WIDTH 64
#define PANEL_HEIGHT 32
// Inizializzazione del pannello LED
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, PANEL_WIDTH);
// Definizione dei pin per i pulsanti
#define BUTTON_1 6
#define BUTTON_2 7
void setup() {
// Configura i pin dei pulsanti come input con pullup interno
pinMode(BUTTON_1, INPUT_PULLUP);
pinMode(BUTTON_2, INPUT_PULLUP);
// Debug seriale
Serial.begin(9600);
Serial.println("Inizializzazione completa. LED spenti.");
// Avvia il pannello LED
matrix.begin();
matrix.fillScreen(0); // Spegne tutti i LED
}
void loop() {
// Controlla se il pulsante 1 è premuto
if (digitalRead(BUTTON_1) == LOW) {
matrix.fillScreen(0); // Spegne tutti i LED
}
// Controlla se il pulsante 2 è premuto
if (digitalRead(BUTTON_2) == LOW) {
drawRightArrow(); // Disegna una freccia verso destra
}
}
// Funzione per disegnare una freccia verso destra
void drawRightArrow() {
matrix.fillScreen(0); // Pulisce lo schermo
uint16_t color = matrix.Color333(7, 0, 0); // Colore bianco
// Disegna il corpo della freccia
for (int y = 8; y < 24; y++) {
for (int x = 0; x < 40; x++) {
matrix.drawPixel(x, y, color);
}
}
// Disegna la punta della freccia
drawTriangle(40, 3, 40, 28, 63, 15, color);
fillTriangle(40, 3, 40, 28, 63, 15, color);
}
// Funzione per disegnare il contorno della punta della freccia
void drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color) {
matrix.drawLine(x1, y1, x2, y2, color); // Linea da (x1, y1) a (x2, y2)
matrix.drawLine(x2, y2, x3, y3, color); // Linea da (x2, y2) a (x3, y3)
matrix.drawLine(x3, y3, x1, y1, color); // Linea da (x3, y3) a (x1, y1)
}
// Funzione per riempire la punta della freccia
void fillTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color) {
int minX = min(x1, min(x2, x3));
int maxX = max(x1, max(x2, x3));
int minY = min(y1, min(y2, y3));
int maxY = max(y1, max(y2, y3));
for (int y = minY; y <= maxY; y++) {
for (int x = minX; x <= maxX; x++) {
if (isPointInTriangle(x, y, x1, y1, x2, y2, x3, y3)) {
matrix.drawPixel(x, y, color);
}
}
}
}
// Funzione per verificare se un punto è all'interno del triangolo
bool isPointInTriangle(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
int d1, d2, d3;
bool hasNeg, hasPos;
d1 = sign(x, y, x1, y1, x2, y2);
d2 = sign(x, y, x2, y2, x3, y3);
d3 = sign(x, y, x3, y3, x1, y1);
hasNeg = (d1 < 0) || (d2 < 0) || (d3 < 0);
hasPos = (d1 > 0) || (d2 > 0) || (d3 > 0);
return !(hasNeg && hasPos);
}
// Funzione per calcolare il segno di un punto rispetto a una linea
int sign(int x1, int y1, int x2, int y2, int x3, int y3) {
return (x1 - x3) * (y2 - y3) - (x2 - x3) * (y1 - y3);
}
Did you connect each panels to the Arduino Mega?
If so, this is not a correct connection. The panels are connected in series, this is called "chaining". To do so, each panel has two HUB75 connectors - INPUT and OUTPUT:
You have to connect microcontroller to the INPUT connector of the first panel, and connect the OUTPUT connector to the INPUT of next panel, and so on.
Depending on your controller, you can connect a different number of panels this way, creating larger screens
Unfortunately, the RGBmatrixPanel.h
library does not support chaining, so you cannot connect more than one panel to it
Ty for the advise.
I'm trying to make a program where I have 3 buttons:
- Button 1 turns off all the dot matrix LEDs;
- Button 2 turns on the dot matrix LED panel 1 and turns off the dot matrix LEDs activated by button 3;
- Button 3 turns on the dot matrix LED panel 2 and turns off the dot matrix LEDs activated by button 2;
- When a dot matrix LED panel is turned on, an arrow must appear on the panel;
- On panel 1, the arrow must point to the left;
- On panel 2, the arrow must point to the right;
- The size of the panels is 64x32;
- The Arduino board used is Arduino Mega;
Do you think it is possible to do this somehow?
I think that the Arduino Mega is not very suitable for this.
First, as I said, the RGBmatrixPanel.h
library does not support more than one panel. It is possible that the library can be changed (if you understand the code) or you can look for another one.
But besides this, each 64x32 panel requires a 3 kB buffer in RAM, that is, for two panels you need 6 kB, and the Mega only has 8
I would choose some other board for working with matrices, for example, esp32 or rp2040
Do you think this is good to use with arduino? AZDelivery Scheda di Sviluppo ESP32 NodeMCU WiFi CP2102 - Compatibile con Arduino - ESP32 WROOM - WiFi Dual-Mode a 2,4 GHz e Bluetooth WiFi - eBook Incluso : Amazon.it: Elettronica
if this is ok do you have any advice on which library to use?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.