'''
Hi i am really tired of serching so i have problem with 16x32 P10-2727-Matrix a pack of 4 horizontaly so a simple sys to print text on lcd and matrix with button.now i used the rgbmatrixpanel.h from adafruit but for some reason nothing appears on the Matrix (the wirdest thing is the test codes inluded in the liberary work just perfect !!!) so i serch for solution and i found a modefied version of this liberary and acctuly it worked but have problem the text not appear correctly it looks like the font size small so it like dots maybe but i try everything i know and no hope so i need some help if anyone can
'''
<
#include <RGBmatrixPanel.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>
// Define HUB75E matrix pins (for 16x32 matrix)
#define CLK 11
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
// Define button pins
#define BUTTON_1_PIN 3
#define BUTTON_2_PIN 4
#define BUTTON_3_PIN 5
#define BUTTON_4_PIN 6
#define BUTTON_5_PIN 7
// Button press settings
#define LONG_PRESS_TIME 3000 // 3 seconds for shutdown
#define DEBOUNCE_DELAY 50 // Debounce delay for stable button reading
// Initialize display (16x32 matrix setup)
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false, 1);
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Command texts and colors
const char* commands[] = {"<<<<<<", "Follow me", "Slow down", "STOP", ">>>>>>"};
uint16_t colors[] = {matrix.Color333(0, 7, 7), matrix.Color333(0, 7, 0),
matrix.Color333(7, 7, 0), matrix.Color333(0, 0, 7),
matrix.Color333(0, 7, 7)};
bool systemOn = true;
unsigned long buttonPressTime[5] = {0, 0, 0, 0, 0};
unsigned long lastDebounceTime[5] = {0, 0, 0, 0, 0};
bool buttonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};
bool lastButtonState[5] = {HIGH, HIGH, HIGH, HIGH, HIGH};
// Font configuration
int textSize = 1; // Default text size (1 = normal)
bool isBold = false; // Default to non-bold text
void setup() {
// Set up pins and initialize displays
pinMode(BUTTON_1_PIN, INPUT_PULLUP);
pinMode(BUTTON_2_PIN, INPUT_PULLUP);
pinMode(BUTTON_3_PIN, INPUT_PULLUP);
pinMode(BUTTON_4_PIN, INPUT_PULLUP);
pinMode(BUTTON_5_PIN, INPUT_PULLUP);
lcd.init();
lcd.backlight();
matrix.begin();
displayStartupMessage();
}
void loop() {
if (systemOn) {
checkButtons();
} else {
checkForStartup();
}
}
// Function to display a welcome message on startup
void displayStartupMessage() {
lcd.setCursor(0, 0);
lcd.print("WELCOME TO EGYPT");
matrix.fillScreen(0);
matrix.setTextColor(matrix.Color333(3, 3, 3)); // Red
matrix.setCursor(2, 2);
matrix.print("WELCOME TO EGYPT");
matrix.swapBuffers(true);
delay(5000);
}
// Function to handle button presses and shutdown trigger
void checkButtons() {
int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};
for (int i = 0; i < 5; i++) {
int reading = digitalRead(buttonPins[i]);
if (reading != lastButtonState[i]) {
lastDebounceTime[i] = millis();
}
if ((millis() - lastDebounceTime[i]) > DEBOUNCE_DELAY) {
if (reading != buttonState[i]) {
buttonState[i] = reading;
if (buttonState[i] == LOW) {
buttonPressTime[i] = millis();
} else {
if (millis() - buttonPressTime[i] < LONG_PRESS_TIME) {
updateDisplay(i);
}
buttonPressTime[i] = 0;
}
}
// Check if button is held for shutdown
if (buttonState[i] == LOW && millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
shutdownSystem();
systemOn = false;
}
}
lastButtonState[i] = reading;
}
}
// Function to update the display based on the command
void updateDisplay(int commandIndex) {
// Update LCD to show command
lcd.clear();
lcd.setCursor(4, 1);
lcd.print(commands[commandIndex]);
// Display command on matrix with sliding animation
matrix.fillScreen(0);
matrix.setTextColor(colors[commandIndex]);
// Set font size (scale text size)
matrix.setTextSize(textSize);
// If bold, simulate boldness by printing text multiple times with offset
if (isBold) {
for (int i = 0; i < 2; i++) {
matrix.fillScreen(0);
matrix.setCursor((128 - strlen(commands[commandIndex]) * 6) / 2 + i, 0); // Slight offset for bold effect
matrix.print(commands[commandIndex]);
matrix.swapBuffers(true);
delay(50);
}
} else {
matrix.setCursor((128 - strlen(commands[commandIndex]) * 6) / 2, 0);
matrix.print(commands[commandIndex]);
matrix.swapBuffers(true);
delay(50);
}
}
// Function to shut down the system and display GOOD BYE message
void shutdownSystem() {
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("GOOD BYE");
matrix.fillScreen(0);
matrix.setTextColor(matrix.Color333(7, 0, 0)); // Red
matrix.setCursor(40, 5);
matrix.print("GOOD BYE");
matrix.swapBuffers(true);
delay(2000); // Show GOOD BYE for 2 seconds
lcd.clear();
lcd.noBacklight();
matrix.fillScreen(0);
}
// Function to check for system startup after shutdown
void checkForStartup() {
int buttonPins[] = {BUTTON_1_PIN, BUTTON_2_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_5_PIN};
for (int i = 0; i < 5; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
if (millis() - buttonPressTime[i] > LONG_PRESS_TIME) {
lcd.backlight();
displayStartupMessage();
systemOn = true;
updateDisplay(0); // Default to first command
break;
}
} else {
buttonPressTime[i] = 0;
}
}
}
Blockquote