Wiring Diagram
#include <SoftwareSerial.h> #include <Adafruit_GFX.h> // Core graphics library #include <RGBmatrixPanel.h> // Hardware-specific library #include <Wire.h> #include "GravityRtc.h" SoftwareSerial Serial1(10, 11); GravityRtc rtc; #define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega) #define LAT A3 #define OE 9 #define A A0 #define B A1 #define C A2 RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false); char col; unsigned int PMSa = 0, FMHDSa = 0, TPSa = 0, HDSa = 0, PMSb = 0, FMHDSb = 0, TPSb = 0, HDSb = 0; unsigned int PMS = 0, FMHDS = 0, TPS = 0, HDS = 0, CR1 = 0, CR2 = 0; unsigned char buffer_RTT[40] = {}; //The serial port receives data char tempStr[15]; char* str[] = {"error", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; int r, y, b, z; int model = 1; void setup() { matrix.begin(); rtc.setup(); //rtc.initRtc(2017,9,27,3,16,20,3);//setup time Serial.begin(9600); } void loop() { if (model == 3) { model = 1; } switch (model) { case 1: r = 0; y = 7; b = 0; break; case 2: r = 0; y = 0; b = 7; break; } rtc.update(); while (Serial.available() > 0) //Check whether there is serial data { for (int i = 0; i < 40; i++) //Read serial data { col = Serial.read(); buffer_RTT[i] = (char)col; delay(2); } Serial.flush(); CR1 = (buffer_RTT[38] << 8) + buffer_RTT[39]; CR2 = 0; for (int i = 0; i < 38; i++) CR2 += buffer_RTT[i]; if (CR1 == CR2) //check { PMSa = buffer_RTT[12]; //Read PM2.5 high octet data PMSb = buffer_RTT[13]; //Read PM2.5 low octet data PMS = (PMSa << 8) + PMSb; //PM2.5 data FMHDSa = buffer_RTT[28]; //Read the high octet data FMHDSb = buffer_RTT[29]; //Read the low octet data FMHDS = (FMHDSa << 8) + FMHDSb; //Formaldehyde data TPSa = buffer_RTT[30]; //Read the high octet data TPSb = buffer_RTT[31]; //Read the low temperature 8-bit data TPS = (TPSa << 8) + TPSb; //Temperature data HDSa = buffer_RTT[32]; //Read the humidity high octet data HDSb = buffer_RTT[33]; //Read low humidity eight bits of data HDS = (HDSa << 8) + HDSb; //Humidity data } } matrix.fillScreen(0); // draw some text! // start at top left, with one pixel of spacing matrix.setTextSize(1); // size 1 == 8 pixels high matrix.setCursor(0, 0); matrix.setTextSize(1); matrix.setTextColor(matrix.Color333(0, 7, 0)); if (rtc.hour < 10) { matrix.print('0'); matrix.print(rtc.hour); } else matrix.print(rtc.hour); matrix.print(':'); if (rtc.minute < 10) { matrix.print('0'); matrix.print(rtc.minute); } else matrix.println(rtc.minute); sprintf(tempStr, "%d%d.%d", TPS / 100, (TPS / 10) % 10, TPS % 10); matrix.setTextColor(matrix.Color333(y, r, b)); matrix.setCursor(0, 8); matrix.print(tempStr); matrix.print("C"); matrix.fillRect(30, 9, 30, 2, matrix.Color333(y, r, b)); delay(5000); // draw some text! matrix.fillRect(0, 7, 32, 9, matrix.Color333(0, 0, 0)); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 0, 0)); matrix.print(':'); delay(300); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 7, 0)); matrix.print(':'); matrix.setCursor(6, 8); matrix.setTextColor(matrix.Color333(0, 0, 7)); matrix.print(str[rtc.week]); delay(5000); matrix.fillRect(0, 7, 32, 9, matrix.Color333(0, 0, 0)); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 0, 0)); matrix.print(':'); delay(300); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 7, 0)); matrix.print(':'); matrix.setTextColor(matrix.Color333(y, r, b)); matrix.setCursor(0, 8); if (rtc.month < 10) { matrix.print('0'); matrix.print(rtc.month); } else matrix.print(rtc.month); matrix.print('-'); if (rtc.day < 10) { matrix.print('0'); matrix.print(rtc.day); } matrix.print(rtc.day); delay(5000); matrix.fillRect(0, 7, 32, 9, matrix.Color333(0, 0, 0)); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 0, 0)); matrix.print(':'); delay(300); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 7, 0)); matrix.print(':'); matrix.setTextColor(matrix.Color333(b, r, y)); matrix.setCursor(0, 8); matrix.print(PMS); matrix.print("ug"); delay(5000); matrix.fillRect(0, 7, 32, 9, matrix.Color333(0, 0, 0)); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 0, 0)); matrix.print(':'); delay(300); matrix.setCursor(12, 0); matrix.setTextColor(matrix.Color333(0, 7, 0)); matrix.print(':'); sprintf(tempStr, "%d%d.%d", HDS / 100, (HDS / 10) % 10, HDS % 10); matrix.setTextColor(matrix.Color333(y, r, b)); matrix.setCursor(0, 8); matrix.print(tempStr); matrix.print("%"); delay(5000); model += 1; }