Matrix breaking down

So since the last time many isues was fixed but not this one , it keeps getting vack its prettty simple i plug it in it work and than all of a suden the matrix starts to brake down and goes crazy any idea how to fix it ? Iam using 5v 3a powwer supply to power board , 10 of these matrix dht 11 and i2c
Here is tge code

// Libraries
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
#include <DHT.h> // Correct header file for the Adafruit DHT sensor library
#include <Wire.h>
#include <RTClib.h>

// Constants
const int photoCell = A0; // Analog pin for the photocell
DHT dht(9, DHT11); // DHT11 sensor connected to pin 9
RTC_DS1307 rtc; // Real-time clock object
char daysOfTheWeek[7][12] = {"Nedela","Pondelok", "Utorok", "Streda", "Stvrtok", "Piatok", "Sobota"};
const int pinCS = 10; // Chip select pin for the LED matrix
const int numberOfHorizontalDisplays = 10; // Number of horizontal LED displays
const int numberOfVerticalDisplays = 1; // Number of vertical LED displays
const int wait = 20; // Delay between scrolling updates in milliseconds
const int spacer = 1; // Space between characters in the matrix display
const int width = 5 + spacer; // Character width including spacer
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

// Variables
int chk, length, brLevel, photoCellValue, count = 0; // General-purpose variables
float hum = 0, temp = 0; // Humidity and temperature readings
String msg; // Message to display
boolean autoBR = true; // Auto-brightness control flag
unsigned long previousMillis = 0; // Timer for content updates
unsigned long lastDHTReadMillis = 0; // Timer for DHT11 readings
const unsigned long DHTReadInterval = 2000; // Minimum interval between DHT11 reads
String tickerText = "made in Matejovce "; // Ticker text for scrolling

void setup() {
Serial.begin(9600); // Initialize Serial communication for debugging
rtc.begin(); // Initialize RTC
// rtc.adjust(DateTime(2017, 03, 21, 19, 47, 0)); // Uncomment to set RTC time
matrix.setIntensity(1); // Set initial brightness to low (1 out of 15)
dht.begin(); // Initialize DHT sensor
}

void loop() {
initMatrix(); // Set up matrix positions and rotations
unsigned long currentMillis = millis(); // Get the current time

// Update thermometer and photoCell variables at appropriate intervals
if (currentMillis - lastDHTReadMillis >= DHTReadInterval) {
lastDHTReadMillis = currentMillis;
hum = dht.readHumidity(); // Read humidity
temp = dht.readTemperature(); // Read temperature
controlBR(); // Adjust brightness based on photocell or manual setting
}

// Show content at regular intervals
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
count++; // Increment counter for seconds
}

// Display different content based on the current counter value
if (count >= 0 && count < 5) {
time(); // Display time
}
else if (count >= 5 && count < 8) {
today(); // Display day of the week
}
else if (count >= 8 && count < 11) {
date(); // Display date
}
else if (count >= 11 && count < 14) {
temperature(); // Display temperature
}
else if (count >= 14 && count < 17) {
humidity(); // Display humidity
}
else if (count >= 17) {
scroll(); // Scroll ticker text
count = 0; // Reset counter
}
}

// Brightness control function
void controlBR() {
if (autoBR) {
photoCellValue = analogRead(photoCell); // Read photocell value
photoCellValue = map(photoCellValue, 1023, 0, 0, 13); // Map to brightness levels
matrix.setIntensity(photoCellValue); // Adjust matrix brightness
}
else {
matrix.setIntensity(brLevel); // Set manual brightness level
}
}

// Display current time
void time() {
DateTime now = rtc.now(); // Get current time
int HH = now.hour();
int MM = now.minute();
int SS = now.second();
msg = (HH < 10) ? "0" + String(HH) + ":" : String(HH) + ":"; // Format hours
msg += (MM < 10) ? "0" + String(MM) + ":" : String(MM) + ":"; // Format minutes
msg += (SS < 10) ? "0" + String(SS) : String(SS); // Format seconds
length = msg.length() * width;
matrix.setCursor((numberOfHorizontalDisplays * 8 - length) / 2, 0); // Center text
matrix.fillScreen(LOW);
matrix.print(msg); // Print time
matrix.write(); // Update matrix
}

// Display day of the week
void today() {
DateTime now = rtc.now(); // Get current date
msg = daysOfTheWeek[now.dayOfTheWeek()]; // Get day of the week
length = msg.length() * width;
matrix.setCursor((numberOfHorizontalDisplays * 8 - length) / 2, 0); // Center text
matrix.fillScreen(LOW);
matrix.print(msg); // Print day
matrix.write(); // Update matrix
}

// Display date
void date() {
DateTime now = rtc.now(); // Get current date
int dd = now.day();
int mm = now.month();
int yyyy = now.year();
msg = (dd < 10) ? "0" + String(dd) + ":" : String(dd) + ":"; // Format day
msg += (mm < 10) ? "0" + String(mm) + ":" : String(mm) + ":"; // Format month
msg += String(yyyy); // Add year
length = msg.length() * width;
matrix.setCursor((numberOfHorizontalDisplays * 8 - length) / 2, 0); // Center text
matrix.fillScreen(LOW);
matrix.print(msg); // Print date
matrix.write(); // Update matrix
}

// Display temperature
void temperature() {
msg = "Temp: " + String(temp) + "oC"; // Format temperature
length = msg.length() * width;
matrix.setCursor((numberOfHorizontalDisplays * 8 - length) / 2, 0); // Center text
matrix.fillScreen(LOW);
matrix.print(msg); // Print temperature
matrix.write(); // Update matrix
}

// Display humidity
void humidity() {
msg = "Hum: " + String(hum) + "%"; // Format humidity
length = msg.length() * width;
matrix.setCursor((numberOfHorizontalDisplays * 8 - length) / 2, 0); // Center text
matrix.fillScreen(LOW);
matrix.print(msg); // Print humidity
matrix.write(); // Update matrix
}

// Scroll ticker text
void scroll() {
for (int i = 0; i < width * tickerText.length() + matrix.width() - 1 - spacer; i++) {
matrix.fillScreen(LOW); // Clear matrix
int letter = i / width; // Determine the current letter
int x = (matrix.width() - 1) - i % width; // Calculate x position
int y = (matrix.height() - 8) / 2; // Center text vertically

while (x + width - spacer >= 0 && letter >= 0) {
  if (letter < tickerText.length()) {
    matrix.drawChar(x, y, tickerText[letter], HIGH, LOW, 1); // Draw character
  }
  letter--;
  x -= width; // Move to the next character position
}
matrix.write(); // Update matrix
delay(wait - 10); // Reduced delay for smoother scrolling

}
}

// Initialize matrix positions and rotations
void initMatrix() {
// Set positions for each display module
matrix.setPosition(0, 9, 0);
matrix.setPosition(1, 8, 0);
matrix.setPosition(2, 7, 0);
matrix.setPosition(3, 6, 0);
matrix.setPosition(4, 5, 0);
matrix.setPosition(5, 4, 0);
matrix.setPosition(6, 3, 0);
matrix.setPosition(7, 2, 0);
matrix.setPosition(8, 1, 0);
matrix.setPosition(9, 0, 0);

// Set rotations for each display module
matrix.setRotation(0, 0);
matrix.setRotation(1, 0);
matrix.setRotation(2, 0);
matrix.setRotation(3, 0);
matrix.setRotation(4, 0);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please edit your post to add code tags. For hardware problems, please post a complete wiring diagram (hand drawn is preferred), with pins, parts and connections clearly labeled.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.