#1 11-02-2021 21:23:37

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Переделал схему подключения матрицы под библиотеку PxMatrix.h
https://github.com/2dom/PxMatrix
Матрица работает.
С PxMatrix.h две матрицы P3-32S-HL1.2. 64x64 работают у меня довольно стабильно. Решил матрицу P5(2121)3264-16S-M1 64x32 тоже перевести на PxMatrix.h

Схема подключения P5(2121)3264-16S-M1 к ESP32.
PI    ESP32 GPIO
А            19
B            23
C            18
D            5
E            15
LAT            22
P_OE    16
CLK            14
R1            13
P5-ESP32.jpg

Схема соединения входного гнезда матрицы(PI) и выходного гнезда матрицы (PO)
PI    PO
R2    R1
G1    R2
G2    G1
B1    G2
B2    B1

P5-PI-PO.gif

Не в сети

#2 11-02-2021 21:31:01

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Перемычек на плате много, целых 9 штук, разводил под распиновку примеров из библиотеки PxMatrix. Плата однослойная и может быть легко изготовлена  в домашних условиях по технологии ЛУТ. Девайс, получился очень стабильный. Ни одного бага, всё работает чётко и ровно.
16130536243314584863717870788395.jpg

16130536761082043734546773330079.jpg

1613053769402862511121779827561.jpg

Не в сети

#3 11-02-2021 21:43:13

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Сегодня, мне удалось запустить матрицу на максимальную скорость. Помог пример double_buffer из библиотеки PxMatrix.h
С такой скоростью, мне ещё не удавалось эту матрицу использовать. Сделал звуковой VU-измеритель, даже пришлось быдлозадержку delay в код вставить, чтоб медленней изображение прокручивалось.

Не в сети

#4 11-02-2021 22:09:47

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

16130554917157157488222284165940.jpg

16130555577832363732942573641068.jpg

Не в сети

#5 11-02-2021 22:15:02

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

16130561802044452046891762300163.jpg

16130562743713205910370392046898.jpg

16130563046712211181506268611361.jpg

16130563352066334393034621471497.jpg

16130563615473183176470167466067.jpg

16130563901806438534367531164389.jpg

1613056439495768956443506396324.jpg

Не в сети

#6 11-02-2021 22:22:34

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Код VU-метра.

#include <math.h> 
#define double_buffer
#include <PxMatrix.h>
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_E 15
#define P_OE 16
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
// Pins for LED MATRIX
PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
void IRAM_ATTR display_updater(){
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);
  display.display(20);
  portEXIT_CRITICAL_ISR(&timerMux);
}
struct Text {
	char *text;
	uint16_t width, height;
	int16_t x, y;
	int16_t dx, dy;
} text = {"Hello", 0, 0, 0, 0, 1, 1};
uint16_t RED = display.color565(225, 0, 0);
uint16_t GREEN = display.color565(0, 255, 0);
uint16_t BLUE = display.color565(0, 0, 255);
uint16_t YELLOW = display.color565(255, 255, 0);
uint16_t textColor = display.color565(225, 0, 0);
uint16_t myBLACK = display.color565(0, 0, 0);
uint16_t lineColor = display.color565(0, 255, 0);
uint16_t backgroundColor = display.color565(0, 255, 0);
int a=0;
int aa=0;
int amp=0;
int ampl=0;
int amp1=0;
int ampl1=0;
int mas[31];
/////////////////////////////////////////////////////////////////////////
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
 for (a = 0; a < 32; a++) mas[a]=0;
  display.begin(16);
  display.flushDisplay();
  display.setTextWrap(false);
    timer = timerBegin(0, 80, true);
    timerAttachInterrupt(timer, &display_updater, true);
    timerAlarmWrite(timer, 4000, true);
    timerAlarmEnable(timer);
  int16_t x1 = 0, y1 = 0;
  display.getTextBounds(text.text, 0, 0, &x1, &y1, &text.width, &text.height);
  text.width-=2;
  text.height-=2;
}
int16_t x=0, dx=1;
void loop() {
  display.fillScreen(myBLACK);
  amp=analogRead(35);
   amp1=analogRead(34);
  amp=fabs(amp-1950);
  amp1=fabs(amp1-1950);  
   ampl1=round(amp1/15);
////////////////////печать данных на экран
a=0;
while (a<32){
 display.drawLine(0,a,mas[a] ,a, lineColor);
  a++; } 
  display.showBuffer();
 ///////////////////////////сдвиг массива
 //for (a = 0; a>31; a++) {
a=0;
 while (a<32){
 mas[a]= mas[a+1];
  a++;
  } 
if (ampl1<10) ampl1=0;
mas[31]=ampl1;
 delay(20);
}
double ReadVoltage(byte pin){
  double reading = analogRead(pin); // Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
  if(reading < 1 || reading > 4095) return 0;
  return -0.000000000000016 * pow(reading,4) + 0.000000000118171 * pow(reading,3)- 0.000000301211691 * pow(reading,2)+ 0.001109019271794 * reading + 0.034143524634089;
} 

Не в сети

#7 11-02-2021 22:48:28

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Схема VU-метра.

P5-ESP32-ADC-VU.gif

Не в сети

#8 11-02-2021 22:51:08

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Звуковой сигнал можно взять с линейного выхода звуковой карты ПК или телефона. Максимальное амплитудное напряжение сигнала 3,3 В.

Не в сети

#9 12-02-2021 00:23:25

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Код быстрого стерео VU метра.

#include <math.h> 
#define double_buffer
#include <PxMatrix.h>
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_E 15
#define P_OE 16
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
// Pins for LED MATRIX
PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
void IRAM_ATTR display_updater(){
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);
  display.display(20);
  portEXIT_CRITICAL_ISR(&timerMux);
}
struct Text {
	char *text;
	uint16_t width, height;
	int16_t x, y;
	int16_t dx, dy;
} text = {"Hello", 0, 0, 0, 0, 1, 1};
uint16_t RED = display.color565(225, 0, 0);
uint16_t GREEN = display.color565(0, 255, 0);
uint16_t BLUE = display.color565(0, 0, 255);
uint16_t YELLOW = display.color565(255, 255, 0);
uint16_t textColor = display.color565(225, 0, 0);
uint16_t myBLACK = display.color565(0, 0, 0);
uint16_t lineColor = display.color565(0, 255, 0);
uint16_t backgroundColor = display.color565(0, 255, 0);
int a=0;
int aa=0;
int amp=0;
int ampl=0;
int amp1=0;
int ampl1=0;
/////////////////////////////////////////////////////////////////////////
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
  display.begin(16);
  display.flushDisplay();
  display.setTextWrap(false);
    timer = timerBegin(0, 80, true);
    timerAttachInterrupt(timer, &display_updater, true);
    timerAlarmWrite(timer, 4000, true);
    timerAlarmEnable(timer);
  int16_t x1 = 0, y1 = 0;
  display.getTextBounds(text.text, 0, 0, &x1, &y1, &text.width, &text.height);
  text.width-=2;
  text.height-=2;
}
int16_t x=0, dx=1;
void loop() {
  display.fillScreen(myBLACK);
  amp=analogRead(35);
   amp1=analogRead(34);
  amp=fabs(amp-1950);
  amp1=fabs(amp1-1950);  
   ampl1=round(amp1/15);
   ampl=round(amp/15);
if (ampl1<9)ampl1=0;
if (ampl<9)ampl=0;
////////////////////печать данных на экран
for (a = 0; a<ampl1; a++){
display.drawLine(a,0,a ,10,GREEN );
if (a>40) display.drawLine(a,0,a ,10,YELLOW );
if (a>55) display.drawLine(a,0,a ,10,RED );
//if (ampl1>50) display.drawLine(a,0,a ,10,YELLOW );
//if (ampl1>58) display.drawLine(a,0,a ,10,RED );
}
for (a = 0; a<ampl; a++){
display.drawLine(a,21,a ,31,GREEN );
if (a>40) display.drawLine(a,21,a ,31,YELLOW );
if (a>55) display.drawLine(a,21,a ,31,RED );
}
  display.showBuffer();
// delay(10);
}
double ReadVoltage(byte pin){
  double reading = analogRead(pin); // Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
  if(reading < 1 || reading > 4095) return 0;
  return -0.000000000000016 * pow(reading,4) + 0.000000000118171 * pow(reading,3)- 0.000000301211691 * pow(reading,2)+ 0.001109019271794 * reading + 0.034143524634089;
} 

Не в сети

#10 12-02-2021 01:09:55

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Код инертного стерео VU метра. Для удобства восприятия графической информации, производим 300 измерений напряжения и транслируем среднее значение. Эмуляция тормозных аналоговых показометров.

#include <math.h> 
#define double_buffer
#include <PxMatrix.h>
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_E 15
#define P_OE 16
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
// Pins for LED MATRIX
PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
void IRAM_ATTR display_updater(){
  // Increment the counter and set the time of ISR
  portENTER_CRITICAL_ISR(&timerMux);
  display.display(20);
  portEXIT_CRITICAL_ISR(&timerMux);
}
struct Text {
	char *text;
	uint16_t width, height;
	int16_t x, y;
	int16_t dx, dy;
} text = {"Hello", 0, 0, 0, 0, 1, 1};
uint16_t RED = display.color565(225, 0, 0);
uint16_t GREEN = display.color565(0, 255, 0);
uint16_t BLUE = display.color565(0, 0, 255);
uint16_t YELLOW = display.color565(255, 255, 0);
uint16_t textColor = display.color565(225, 0, 0);
uint16_t myBLACK = display.color565(0, 0, 0);
uint16_t lineColor = display.color565(0, 255, 0);
uint16_t backgroundColor = display.color565(0, 255, 0);
int a=0;
int aa=0;
int amp=0;
int ampl=0;
int amp1=0;
int ampl1=0;

int ampl1SUM=0;
int  amplSUM=0;

/////////////////////////////////////////////////////////////////////////
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
  display.begin(16);
  display.flushDisplay();
  display.setTextWrap(false);
    timer = timerBegin(0, 80, true);
    timerAttachInterrupt(timer, &display_updater, true);
    timerAlarmWrite(timer, 4000, true);
    timerAlarmEnable(timer);
  int16_t x1 = 0, y1 = 0;
  display.getTextBounds(text.text, 0, 0, &x1, &y1, &text.width, &text.height);
  text.width-=2;
  text.height-=2;
}
int16_t x=0, dx=1;
void loop() {
  display.fillScreen(myBLACK);
 for (a = 0; a<300; a++){
  amp=analogRead(35);
   amp1=analogRead(34);
  amp=fabs(amp-1950);
  amp1=fabs(amp1-1950);  
   ampl1=round(amp1/10);
   ampl=round(amp/10);
  
  ampl1SUM=ampl1SUM+ampl1;
  amplSUM=amplSUM+ampl;
 }
ampl1SUM=ampl1SUM/300;
 amplSUM=amplSUM/300;
//if (ampl1<9)ampl1=0;
//if (ampl<9)ampl=0;
////////////////////печать данных на экран
for (a = 0; a<ampl1SUM; a++){
display.drawLine(a,0,a ,10,GREEN );
if (a>40) display.drawLine(a,0,a ,10,YELLOW );
if (a>55) display.drawLine(a,0,a ,10,RED );
//if (ampl1>50) display.drawLine(a,0,a ,10,YELLOW );
//if (ampl1>58) display.drawLine(a,0,a ,10,RED );
}
for (a = 0; a<amplSUM; a++){
display.drawLine(a,21,a ,31,GREEN );
if (a>40) display.drawLine(a,21,a ,31,YELLOW );
if (a>55) display.drawLine(a,21,a ,31,RED );
}
  display.showBuffer();
// delay(10);
}
double ReadVoltage(byte pin){
  double reading = analogRead(pin); // Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
  if(reading < 1 || reading > 4095) return 0;
  return -0.000000000000016 * pow(reading,4) + 0.000000000118171 * pow(reading,3)- 0.000000301211691 * pow(reading,2)+ 0.001109019271794 * reading + 0.034143524634089;
} 

Не в сети

#11 12-02-2021 01:18:50

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

16130673803292453620498474924522.jpg

16130674226455863556974543245885.jpg

16130674747661488670479008255969.jpg

Не в сети

#12 19-02-2021 16:55:10

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Очередные NTP часы.
16137282712212643508082101828542.jpg

16137283632294253698854284781290.jpg

16137284412205407879837765243732.jpg

Не в сети

#13 19-02-2021 16:57:35

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

Код.

#include <IRremote.h>
IRrecv IrReceiver(27);
#include <Adafruit_GFX.h>
#include <Fonts/Org_01.h>
#include "Arduino.h"
#include <ESPPerfectTime.h>
#include <TimeLib.h> // Time library https://github.com/PaulStoffregen/Time
#include <WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoJson.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 2//ВХОД DS18B20
OneWire oneWire_in(ONE_WIRE_BUS_1);
DallasTemperature sensor_inhouse(&oneWire_in);
#include <PxMatrix.h>
// Pins for LED MATRIX ESP32
#include <Ticker.h>
Ticker display_ticker;
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_OE 16
#define matrix_width 32
#define matrix_height 64
void tempTask(void *pvParameters);
bool getTemperature();
void triggerGetTemp();
/** Task handle for the light value read task */
TaskHandle_t tempTaskHandle = NULL;
/** Ticker for temperature reading */
Ticker tempTicker;
/** Flag if task should run */
bool tasksEnabled = false;
int iwifi=0;
int R=255;
int B=255;
int G=255;
String DAY="";
int MON=0;
int GOD=0;
int sec=0;
int minuts=0;
int CHAS=0;
float tempC =0;
float tempC1 =0;
float tempC11 =0;
float tempC12 =0;
uint8_t display_draw_time=20; //10-50 is usually fine
PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
char ssid[] = "tele2";  //  your network SSID (name)
char pass[] = "ta20242024";// your network password
// NTP configuration
const char *ntpServerName = "pool.ntp.org";
const int timeZone = 0;     // UTC
const int daylightOffset_sec = 3600; // DST offset in seconds
// Other variables and objects
WiFiClient wifiClient;
char timeZoneAbbreviation[10];
char timeZone_str[40];
time_t prevDisplay = 0; // when the digital clock was displayed
void display_updater()
{
  display.display(display_draw_time);
}
void display_update_enable(bool is_enable)
{
 if (is_enable)
    display_ticker.attach(0.002, display_updater);
  else
    display_ticker.detach();
}
// Начало функции обработки кириллических символов
String utf8rus(String source)     // Функция для конвертации русских символов из кодировки CP1251 в UTF8
{
  int i,k;
  String target;
  unsigned char n;
  char m[2] = { '0', '\0' };
  k = source.length(); i = 0;
  while (i < k) {
    n = source[i]; i++;
 
    if (n >= 0xBF){
      switch (n) {
        case 0xD0: {
          n = source[i]; i++;
          if (n == 0x81) { n = 0xA8; break; }
          if (n >= 0x90 && n <= 0xBF) n = n + 0x2F;
          break;
        }
        case 0xD1: {
          n = source[i]; i++;
          if (n == 0x91) { n = 0xB7; break; }
          if (n >= 0x80 && n <= 0x8F) n = n + 0x6F;
          break;
        }
      }
    }
    m[0] = n; target = target + String(m);
  }
  return target;
}
// Конец функции обработки кириллических симоволов
long density = 20;
int polltime;
void setup()///////////////////////////////////////////////////////////////////////////////////
{
randomSeed(analogRead(0));
 Serial.begin(115200);
 IrReceiver.enableIRIn();  // Start the receiver
tasksEnabled = true;
delay(500);
sensor_inhouse.begin();
 delay(500);
  // Define your display layout here, e.g. 1/8 step, and optional SPI pins begin(row_pattern, CLK, MOSI, MISO, SS)
  display.begin(16);
 delay(500);
  display.setFastUpdate(true);
  display.clearDisplay();
   display_update_enable(true);
// Connect to WiFi SSID
  connectWiFi();
// Request http://worldtimeapi.org/api/ip
  DynamicJsonDocument jsonDoc = httpJSONRequest(wifiClient, "worldtimeapi.org", "/api/ip");
strcpy(timeZoneAbbreviation, jsonDoc["abbreviation"]);
  bool dst = jsonDoc["dst"]; // true
  int dst_offset = jsonDoc["dst_offset"]; // 3600
  strcpy(timeZone_str, jsonDoc["timezone"]);
  const char* utc_offset = jsonDoc["utc_offset"]; // "+01:00"
  float utc_offset_float = ((float)utc_offset[1] - 48) * 10 + ((float)utc_offset[2] - 48) + (((float)utc_offset[4] - 48) * 10 + ((float)utc_offset[5] - 48)) / 60.0;
  if ((int)utc_offset[0] == 45)  {
    utc_offset_float *= -1;
  }
 Serial.println(timeZoneAbbreviation);
  Serial.println(dst);
  Serial.println(timeZone_str);
  Serial.println(utc_offset);
  Serial.println(utc_offset_float);
  Serial.println("СЕТАП");
  pftime::configTime(utc_offset_float * 3600, 0, ntpServerName);
}
/////////////////////////////////////////////END SETUP//////////////////////
union single_double{
  uint8_t two[2];
  uint16_t one;
} this_single_double;
unsigned long last_draw=0;
uint8_t icon_index=0;
////////////////////////////////////////////////////////////////////////////////////
void STROKA()
{//////////////////бегущая строка/////////
randomRGB();
display.setFont(&Org_01);
display.setTextSize(6);
    display.setTextColor(display.color565(R,B,G));
  for (int y=0; y<75;y++)
  {
display.clearDisplay();
display.setCursor(0-y ,25); 
display.print(CHAS);
    display.print(":");
   if (minuts<10) display.print("0");
   display.print(minuts);
delay(25);
  } 
randomRGB();
 for (int y=75; y>0;y--)
  {
display.clearDisplay();
display.setCursor(0-y ,25); 
display.print(CHAS);
    display.print(":");
  if (minuts<10) display.print("0");
   display.print(minuts);
delay(25);
  } 
delay(1500);
display.clearDisplay();
}
void DATA()
{
 display.setTextSize(2);
 randomRGB();
   display.setTextColor(display.color565(R,B,G));
  display.setCursor(0,30);
display.print(DAY);
display.print(".");
display.print(MON);
display.print(".");
display.setTextSize(1);
display.print(GOD);
}
void SHOWTIME()
{
display.clearDisplay();
 randomRGB();
display.setFont(&Org_01);
   display.setTextSize(3); 
   display.setTextColor(display.color565(R,B,G));
  display.setCursor(0 ,12);
  if (CHAS==11){
  display.setCursor(8 ,12);
  }
 display.print(CHAS);
    display.print(":");
  if (CHAS>19) display.setTextSize(2); 
   if (minuts<10) display.print("0");
   display.print(minuts);
}
void TIME()
{
 if (now() != prevDisplay) { //update the display only if time has changed
    prevDisplay = now();
    // Get current local time as struct tm by calling pftime::localtime(nullptr)
    struct tm *tm = pftime::localtime(nullptr);
    // Get microseconds at the same time by passing suseconds_t* as 2nd argument
    suseconds_t usec;
    tm = pftime::localtime(nullptr, &usec);
    // Get the time string
    String dateString = getDateString(tm, usec);
    String timeString = getTimeString(tm, usec);
/////////////////секундная линия////
display.drawLine(sec+1,17,sec+1 ,19,display.color565(R,B,G));
////////////////////////////////////
if ((sec==0) and ((minuts==0)or(minuts==15)or(minuts==30)or(minuts==45))){
STROKA();
SHOWTIME();
DATA();
}
////////////////////////
if (sec==0){
  SHOWTIME();
  DATA();
}
}  
}
void randomRGB()
{
  R=random(255);
  G=random(255);
  B=random(255);
if (R+G+B<255)  G=255;
}
void loop() 
{ 
if (IrReceiver.decode()) {
        IrReceiver.printResultShort(&Serial);
        Serial.println();

        IrReceiver.resume(); // Receive the next value
    }
TIME();
 if (WiFi.status() == WL_CONNECTED){
  delay(1000);
  WiFi.disconnect();
 }
////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void connectWiFi() {
  WiFi.disconnect();
  WiFi.mode(WIFI_MODE_STA);
  WiFi.begin(ssid, pass);
  Serial.print("\nConnecting to WiFi SSID " + String(ssid) + " ...");
  while (WiFi.status() != WL_CONNECTED and iwifi<15) {
    iwifi++;
    Serial.print(".");
   display.setTextSize(0);
   display.setTextColor(display.color565(40,0,0));
   delay(1000);
 display.drawPixel(0+iwifi, 63, display.color565(20,0,0));
  }
  Serial.println("\nConnected. ");
  Serial.print("The IP number assigned by DHCP is ");
  Serial.println(WiFi.localIP());  
}
String getDateString(struct tm *tm, suseconds_t usec) {
  char time_string[100];
  sprintf(time_string, "%02d.%02d.%04d",
          tm->tm_mday,
          tm->tm_mon + 1,
          tm->tm_year + 1900);
DAY=(tm->tm_mday);
MON=(tm->tm_mon + 1);
GOD=(tm->tm_year + 1900);
return time_string;
}
String getTimeString(struct tm *tm, suseconds_t usec) {
  char time_string[100];
 sprintf(time_string, "%02d:%02d",
          tm->tm_hour,
          tm->tm_min);
 //Serial.println(tm->tm_sec);
 sec=(tm->tm_sec);
 minuts=(tm->tm_min);
 CHAS=(tm->tm_hour);
  return time_string;
}

Не в сети

#14 19-02-2021 17:01:22

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

В одной папке с основным кодом, должны быть файлы worldtimeapi.ino и http_json_request.ino
Код файла worldtimeapi.ino

/* http://worldtimeapi.org/api/ip
 * {"abbreviation":"BST",
 * "client_ip":"86.17.220.24",
 * "datetime":"2020-07-25T14:51:01.689928+01:00",
 * "day_of_week":6,
 * "day_of_year":207,
 * "dst":true,
 * "dst_from":"2020-03-29T01:00:00+00:00",
 * "dst_offset":3600,
 * "dst_until":"2020-10-25T01:00:00+00:00",
 * "raw_offset":0,
 * "timezone":"Europe/London",
 * "unixtime":1595685061,
 * "utc_datetime":"2020-07-25T13:51:01.689928+00:00",
 * "utc_offset":"+01:00",
 * "week_number":30
 * }
 */

//
//const size_t capacity = JSON_OBJECT_SIZE(15) + 350;
//DynamicJsonDocument doc(capacity);
//
//const char* json = "{\"abbreviation\":\"BST\",\"client_ip\":\"86.17.220.24\",\"datetime\":\"2020-07-25T14:51:01.689928+01:00\",\"day_of_week\":6,\"day_of_year\":207,\"dst\":true,\"dst_from\":\"2020-03-29T01:00:00+00:00\",\"dst_offset\":3600,\"dst_until\":\"2020-10-25T01:00:00+00:00\",\"raw_offset\":0,\"timezone\":\"Europe/London\",\"unixtime\":1595685061,\"utc_datetime\":\"2020-07-25T13:51:01.689928+00:00\",\"utc_offset\":\"+01:00\",\"week_number\":30}";
//
//deserializeJson(doc, json);
//
//const char* abbreviation = doc["abbreviation"]; // "BST"
//const char* client_ip = doc["client_ip"]; // "86.17.220.24"
//const char* datetime = doc["datetime"]; // "2020-07-25T14:51:01.689928+01:00"
//int day_of_week = doc["day_of_week"]; // 6
//int day_of_year = doc["day_of_year"]; // 207
//bool dst = doc["dst"]; // true
//const char* dst_from = doc["dst_from"]; // "2020-03-29T01:00:00+00:00"
//int dst_offset = doc["dst_offset"]; // 3600
//const char* dst_until = doc["dst_until"]; // "2020-10-25T01:00:00+00:00"
//int raw_offset = doc["raw_offset"]; // 0
//const char* timezone = doc["timezone"]; // "Europe/London"
//long unixtime = doc["unixtime"]; // 1595685061
//const char* utc_datetime = doc["utc_datetime"]; // "2020-07-25T13:51:01.689928+00:00"
//const char* utc_offset = doc["utc_offset"]; // "+01:00"
//int week_number = doc["week_number"]; // 30
 

Код файла http_json_request.ino

#include <WiFi.h>
DynamicJsonDocument httpJSONRequest(WiFiClient client, char *hostname, String endpoint) {
  const size_t capacity = JSON_OBJECT_SIZE(15) + 350;
  DynamicJsonDocument doc(capacity);
    // Connect to HTTP server
  client.setTimeout(10000);
  if (!client.connect(hostname, 80)) {
    Serial.println(F("Connection failed"));
    return doc;
  }
  Serial.println(F("HTTP request client connected"));
  // Send HTTP request
  client.print(F("GET /"));
  client.print(endpoint);
  client.println(F(" HTTP/1.0"));
  client.print(F("Host: "));
  client.println(hostname);
  client.println(F("Connection: close"));
  if (client.println() == 0) {
    Serial.println(F("Failed to send request"));
    return doc;
  }
 // Check HTTP status
  char status[32] = {0};
  client.readBytesUntil('\r', status, sizeof(status));
  // It should be "HTTP/1.0 200 OK" or "HTTP/1.1 200 OK"
  if (strcmp(status + 9, "200 OK") != 0) {
    Serial.print(F("Unexpected response: "));
    Serial.println(status);
    return doc;
  }

  // Skip HTTP headers
  char endOfHeaders[] = "\r\n\r\n";
  if (!client.find(endOfHeaders)) {
    Serial.println(F("Invalid response"));
    return doc;
  }

  // Parse the JSON response
  deserializeJson(doc, client);
  return doc;
}

Не в сети

#15 19-02-2021 17:06:12

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

16137289841089115198904556256295.jpg

Не в сети

#16 19-02-2021 22:33:35

IvanAltay
Administrator
Зарегистрирован: 03-05-2018
Сообщений: 4,586

Re: RGB матрица P5(2121)3264-16S-M1 64x32 + ESP32_DEVKItc_V4 + PxMatrix.h

16137487463237652076532965163907.jpg

Не в сети

Подвал раздела

Работает на FluxBB (перевод Laravel.ru)