RGB Led Matrix Clock With Arduino

RGB Matrix p4 with arduino mega 64*32 P4-256*128-2121-A2


RGB Matrix p4 with arduino mega 64x32
DS1307 Real Time Clock
64x32 rgb led matrix arduino
64x32 rgb led matrix arduino code
matrice led rgb arduino
 This project with esp32 
 

Schema


Code

// testshapes demo for RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x64 RGB LED matrix.

// WILL NOT FIT on ARDUINO UNO -- requires a Mega, M0 or M4 board



#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#include <MD_DS1307.h>
#include <Wire.h>
#define CLK 11 // USE THIS ON ARDUINO MEGA
#define OE   9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
// Global variables
#define MAX_MESG  4
#define MAX_MES  20
unsigned int NewRTCh = 24;
unsigned int NewRTCm = 60;
unsigned int NewRTCs = 60;
char szTime[12];    // mm:ss\0
char szMesg[MAX_MESG+1] = "";
char szDate[MAX_MES+1] = "";
char *mon2str(uint8_t mon, char *psz, uint8_t len)
// Get a label from PROGMEM into a char array
{
  static const char str[][4] PROGMEM =
  {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  };

  *psz = '\0';
  mon--;
  if (mon < 12)
  {
    strncpy_P(psz, str[mon], len);
    psz[len] = '\0';
  }

  return(psz);
}

char *dow2str(uint8_t code, char *psz, uint8_t len)
{
  static const char str[][10] PROGMEM =
  {
    "Su", "Mo", "Tu", "We",
    "Th", "Fr", "Sa"
  };

  *psz = '\0';
  code--;
  if (code < 7)
  {
    strncpy_P(psz, str[code], len);
    psz[len] = '\0';
  }

  return(psz);
}
void getTime(char *psz, bool f = true)
// Code for reading clock time
{
 
  RTC.readTime();
    if (NewRTCh != RTC.h) 
  {
  sprintf(psz, "%02d", RTC.h);
  matrix.setCursor(2, 4); 
  matrix.setTextSize(2);
    matrix.setTextColor(matrix.Color333(7, 0, 7));
  matrix.fillRect(2, 4, 64, 14, matrix.Color333(0, 0, 0));
    matrix.print(szTime);
  sprintf(psz, "%02d", RTC.m);
  matrix.setCursor(28, 4); 
    matrix.setTextColor(matrix.Color333(7, 0, 7));
  matrix.fillRect(25, 4, 25, 14, matrix.Color333(0, 0, 0));
    matrix.print(szTime);
  matrix.setCursor(21, 4); 
  matrix.setTextColor(matrix.Color333(7, 0, 0));
  matrix.fillRect(25, 8, 2, 6, matrix.Color333(0, 0, 0));
    matrix.print(f ? ':' : ' ');
  matrix.setCursor(52, 9); 
  matrix.setTextSize(1);
  matrix.setTextColor(matrix.Color333(7, 7, 0));
  matrix.fillRect(52, 9, 11, 7, matrix.Color333(0, 0, 0));
  sprintf(psz, "%02d", RTC.s);
    matrix.print(szTime);
        getDate(szDate);
  matrix.setCursor(5, 20);
  matrix.fillRect(5, 20, 54, 8, matrix.Color333(0, 0, 0));
  uint8_t y = 0;
  for (y=0; y<10; y++) {
    matrix.setTextColor(Wheel(y));
    matrix.print(szDate[y]);
    }
        getDay(szMesg);
  matrix.setTextSize(1);
  matrix.setCursor(52, 1);
  matrix.setTextColor(matrix.Color333(0, 7, 0));
  matrix.fillRect(52, 1, 11, 7, matrix.Color333(0, 0, 0));
    matrix.print(szMesg);
      NewRTCh=RTC.h;
    }
    else if (NewRTCm != RTC.m) 
  {
  sprintf(psz, "%02d", RTC.m);
  matrix.setCursor(28, 4); 
  matrix.setTextSize(2);
    matrix.setTextColor(matrix.Color333(7, 0, 7));
  matrix.fillRect(25, 4, 25, 14, matrix.Color333(0, 0, 0));
    matrix.print(szTime);
  matrix.setCursor(21, 4); 
  matrix.setTextColor(matrix.Color333(0, 0, 7));
  matrix.fillRect(25, 8, 2, 6, matrix.Color333(0, 0, 0));
    matrix.print(f ? ':' : ' ');
  matrix.setCursor(52, 9); 
  matrix.setTextSize(1);
  matrix.setTextColor(matrix.Color333(0, 7, 7));
  sprintf(psz, "%02d", RTC.s);
  matrix.fillRect(52, 9, 11, 7, matrix.Color333(0, 0, 0));
    matrix.print(szTime);
      NewRTCm=RTC.m;
    }
    else if (NewRTCs != RTC.s/10) 
  {
  matrix.setCursor(21, 4); 
  matrix.setTextSize(2);
  matrix.setTextColor(matrix.Color333(0, 7, 0));
  matrix.fillRect(25, 8, 2, 6, matrix.Color333(0, 0, 0));
    matrix.print(f ? ':' : ' ');
  matrix.setCursor(52, 9); 
  matrix.setTextSize(1);
  matrix.setTextColor(matrix.Color333(0, 0, 7));
  sprintf(psz, "%02d", RTC.s);
  matrix.fillRect(52, 9, 11, 7, matrix.Color333(0, 0, 0));
    matrix.print(szTime);
      NewRTCs=RTC.s/10;
    }
    else
  {
  matrix.setCursor(21, 4); 
  matrix.setTextSize(2);
  matrix.setTextColor(matrix.Color333(0, 0, 7));
  matrix.fillRect(25, 8, 2, 6, matrix.Color333(0, 0, 0));
    matrix.print(f ? ':' : ' ');
  matrix.setCursor(52, 9); 
  matrix.setTextSize(1);
  matrix.setTextColor(matrix.Color333(7, 0, 0));
  sprintf(psz, "%02d", RTC.s);
  matrix.fillRect(58, 9, 5, 7, matrix.Color333(0, 0, 0));
    matrix.print(szTime);
    }
  }
void getDate(char *psz)
// Code for reading date
{
  char  szBuf[10];
  sprintf(psz, "%02d%s%04d", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf)-1), RTC.yyyy);
}
void getDay(char *psz)
// Code for reading day date
{
  dow2str(RTC.dow, szMesg, MAX_MESG);
}

void setup() {

  matrix.begin();
  matrix.setTextWrap(false);
  RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
  RTC.control(DS1307_12H, DS1307_OFF);
}

void loop() {
  static uint32_t lastime = 0; // millis() memory
  static bool flasher = false;  // seconds passing flasher
  if (millis() - lastime >= 1000)
  
   {
    lastime = millis();
    getTime(szTime, flasher);
    flasher = !flasher;
  }
 
}


// Input a value 0 to 24 to get a color value.
// The colours are a transition r - g - b - back to r.
uint16_t Wheel(byte WheelPos) {
  if(WheelPos < 2) {
   return matrix.Color333(0, 7, 0);
  } else if(WheelPos < 5) {
   WheelPos -= 2;
   return matrix.Color333(7 , 0, 0);
  } else {
   WheelPos -= 5;
   return matrix.Color333(0, 7, 0);
  }
}

20 comments:

  1. nếu dùng arduino uno r3 hoặc arduino pro mini được không add?

    ReplyDelete
  2. uno hay pro không đủ memory.

    ReplyDelete
    Replies
    1. Bạn ơi, tôi cũng làm cái 32x64 này, mới chỉ chạy demo testshape thôi, pixel ok nhưng mà màu chưa ổn, lên 2 màu R và G, màu B không có. Bạn biết lỗi ở đâu không chỉ mình với.

      Delete
  3. C:\Users\Hang\Desktop\CODE_MOI\CODE_MOI.ino:9:27: fatal error: Adafbean_GFX.h: No such file or directory

    #include
    LỖI GÌ V Ạ,

    ReplyDelete
  4. I have the 16x32 matrix panel which sketch should I use? or what I have to change in the sketch

    ReplyDelete
  5. Hello,

    Can we add one more RGB 64 x 32 to this project and still manage it with the same board ?

    Thanks

    ReplyDelete
  6. Hello,

    Great project. I build it but the day in the top right corner does not show. What could be the problem?

    Regards, Emil

    ReplyDelete
  7. Can i use any arduino board? I have a Nano board.

    ReplyDelete
    Replies
    1. RGB Matrix p4 with arduino mega 64x32
      DS1307 Real Time Clock
      64x32 rgb led matrix arduino
      64x32 rgb led matrix arduino code
      matrice led rgb arduino

      Delete
  8. Great project, but how did you set the correct date and time? "Determine this I cannot."

    ReplyDelete
    Replies
    1. I guess no one replies to any of these questions. Thanks for the help.

      Delete
  9. Hello!
    A great project I did. I can not add setup buttons. I'm new to programming. Also, I like your idea of scrolling text (from the video). But can not write the code!
    Thank you in advance!!!

    ReplyDelete
  10. Unfortunately, the RGBmatrixPanel doesn't currently support LED displays using the FM6126A chip (or does it?). I couldn't make it work, the screen stays off.

    ReplyDelete
  11. 2019 Year End holidays. Good look I will try this project. If success I will share to students in my class. Same I can put on this page as others can view the operation. Wishing to all viewers Happy New Year 2020.

    ReplyDelete
  12. i did an other project with the mega and the 64x32 panel. i could not get it running but the one thing that helped from this project was the wiring diagram. lot of other projects did not show the wiring of the R1,G1,B1,R2,G2,B2 and after
    i connected these the project runs fine. many thanks for this wiring

    ReplyDelete
  13. Hi, is there any limitation for number of leds in matrix display?

    ReplyDelete
  14. Great project. One time run and it works. Many thanks.

    ReplyDelete
  15. how to programmatically change brightness

    ReplyDelete