Разное о выращивании табака на Алтае
Вы не вошли.
Навеяло отсюда.
https://www.youtube.com/watch?v=r2UAmBLBBRM
Спасибо камраду Andreas Spiess.
Исходный код часов, стырил тут же.
https://github.com/SensorsIot/NTP-time- … -and-ESP32
Привинтил его NTP часы к своей матрице P5. Сильно порадовало! Для старта, нужен интернет и доступ к сайту точного времени. Дальше, часы работают автономно(на ресурсах ESP, не нужен даже отдельный модуль точного времени). Часы делают поправку(загружают эталонное время) - один раз в час. Если нет доступа к сети, часы шлёпают сами(как могут). За сутки(без подключения к сети), часы возможно убежали на секунду. Но это я, не смог отследить ТОЧНО! Эксперименты продолжаются...
Не в сети
Не в сети
Не в сети
Не в сети
Скетч рабочий, но ещё в процессе. Глючит считывание с градусника DS18B20. После старта матрицы matrix.begin, данные с DS18B20 не считываются. Можно, регулярно перезапускать ESP , если допустим есть подключение всегда к wifi. Например так ESP.restart(); по таймеру.
//////////////////////////////////////
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS_1 13//ПОРТ ПОДКЛЮЧЕНИЯ DS18B20
#include <WiFi.h>
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
#include <Fonts/FreeSansBold18pt7b.h>
OneWire oneWire_in(ONE_WIRE_BUS_1);
DallasTemperature sensor_inhouse(&oneWire_in);
String TEMP = "";
String TEMP1 = "";
P3RGB64x32MatrixPanel matrix;
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#include <time.h>
int boo = 1;
int a = 0;
int t = 0;
int t1 = 0;
int R = 0;
int G = 1;
int B = 0;
int TS = 1;
int t2 = 0;
int t3 = 0;
float tempC1;
float tempC;
#ifdef CREDENTIALS
const char* ssid = mySSID;
const char* password = myPASSWORD;
#else
const char* ssid = "tele2";
const char* password = "ta20242024";
#endif
const char* NTP_SERVER = "ch.pool.ntp.org";
const char* TZ_INFO = "MSK-7MSD,M3.5.0/2,M10.5.0/3"; //"MSK-7MSD,M3.5.0/2,M10.5.0/3"-ЧАСОВОЙ ПОЯС АЛТАЙСКОГО КРАЯ
//"MSK-3MSD,M3.5.0/2,M10.5.0/3"-МОСКОВСКОЕ ВРЕМЯ(https://remotemonitoringsystems.ca/time-zone-abbreviations.php)
tm timeinfo;
time_t now;
long unsigned lastNTPtime;
unsigned long lastEntryTime;
void setup() {
Serial.begin(115200);
Serial.println("\n\nNTP Time Test\n");
WiFi.begin(ssid, password);
int counter = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(200);
if (++counter > 10) ESP.restart();
Serial.print ( "." );
}
Serial.println("\n\nWiFi connected\n\n");
configTime(0, 0, NTP_SERVER);
// See https://github.com/nayarsystems/posix_t … /zones.csv for Timezone codes for your region
setenv("TZ", TZ_INFO, 1);
if (getNTPtime(10)) { // wait up to 10sec to sync
} else {
Serial.println("Time not set");
ESP.restart();
}
showTime(&timeinfo);
lastNTPtime = time(&now);
lastEntryTime = millis();
////////////////////////matrix&ds18b20
sensor_inhouse.requestTemperatures();
float tempC = sensor_inhouse.getTempCByIndex(0);
if (tempC != DEVICE_DISCONNECTED_C)
{
Serial.println("ТЕМПЕРАТУРА 1");
Serial.print(tempC);
}
else float tempC = sensor_inhouse.getTempCByIndex(0);
Serial.print(" ");
TEMP = tempC;
tempC1 = tempC;
matrix.begin();//СТАРТ МАТРИЙЫ
matrix.fillScreen(0);
}
void loop() {
// getTimeReducedTraffic(3600);
getNTPtime(10);
showTime(&timeinfo);
delay(1000);
}
bool getNTPtime(int sec) {
{
uint32_t start = millis();
do {
time(&now);
localtime_r(&now, &timeinfo);
Serial.print(".");
delay(10);
} while (((millis() - start) <= (1000 * sec)) && (timeinfo.tm_year < (2016 - 1900)));
if (timeinfo.tm_year <= (2016 - 1900)) return false; // the NTP call was not successful
Serial.print("now "); Serial.println(now);
char time_output[30];
strftime(time_output, 30, "%a %d-%m-%y %T", localtime(&now));
Serial.println(time_output);
Serial.println();
}
//ПЕЧАТЬ ДАННЫХ НА МАТРИЦЕ
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(0, 0, 4));//ЦВЕТ ТЕКСТА RGB ОТ 1 ДО 15
matrix.setFont();
matrix.setTextSize(TS);
matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
matrix.setCursor(0, 0);
matrix.print(localtime(&now));
matrix.setTextColor(matrix.color444(R, G, B));
matrix.setCursor(-130, 8);
matrix.setTextSize(2);
matrix.print(localtime(&now));
matrix.setTextSize(TS);
matrix.setCursor(-95, 24);
matrix.print(localtime(&now));
matrix.setTextColor(matrix.color444(3, 0, 0));
Serial.println("ТЕМПЕРАТУРА");
Serial.println(tempC);
/////////////////////////////
if (t1>120) //СЧИТАЕМ 120 СЕКУНД И ПОКАЗЫВАЕМ ВРЕМЯ КРУПНЫМ ШРИФТОМ В БЕГУЩЕЙ СТРОКЕ
{
matrix.setFont(&FreeSansBold18pt7b);
// matrix.setCursor(-200, 28);
G=6;
matrix.setTextColor(matrix.color444(R, G, B));
while ( a < 30) {
matrix.fillScreen(0);
matrix.print(localtime(&now));
a=a+1;
matrix.setCursor(-180-a, 28);
}
a=0;
delay(1000);
while ( a < 30) {
matrix.fillScreen(0);
matrix.print(localtime(&now));
a=a+1;
matrix.setCursor(-210+a, 28);
}
delay(800);
a=0;
t1=0;
G=2;
}
t3=t3+1;
t1=t1+1;
t2=t2+1;
Serial.println("t2=");
Serial.println(t2);
Serial.println("tempC1");
Serial.println(tempC1);
if (t2>300)// ОТОБРАЖАЕМ ТЕМЕРАТУРУ КАЖДЫЕ 300 СЕКУНД
{
if (tempC1 > (0))//ЕСЛИ ТЕМПЕРАТУРА ВЫШЕ 0 ГРАДУСОВ, ДОБАВЛЯЕМ ЗНАК +
{
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(3, 0, 0));
matrix.setFont();
matrix.setTextSize(TS);
matrix.setCursor(0,0);
matrix.print("Temperature");
matrix.setCursor(10,12);
matrix.print("+");
matrix.print(TEMP);
matrix.print(" C");
delay(5000);
}
if (tempC < (0)){
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(3, 0, 0));
matrix.setFont();
matrix.setTextSize(TS);
matrix.setCursor(0,0);
matrix.print("Temperature");
matrix.setCursor(10,12);
matrix.print(TEMP+" C");
delay(5000);
}
t2=0;
}
matrix.swapBuffer();
return true;
}
void showTime(tm *localTime) {
Serial.print(localTime->tm_mday);
Serial.print('/');
Serial.print(localTime->tm_mon + 1);
Serial.print('/');
Serial.print(localTime->tm_year - 100);
Serial.print('-');
Serial.print(localTime->tm_hour);
Serial.print(':');
Serial.print(localTime->tm_min);
Serial.print(':');
Serial.print(localTime->tm_sec);
Serial.print(" Day of Week ");
if (localTime->tm_mday = 0) localTime->tm_mday = 7;
Serial.println(localTime->tm_wday);
//ESP.restart();
}
Не в сети
Про подключение светодиодной матрицы P3/P5 подробно тут
https://github.com/NeoCat/ESP32-P3RGB64x32MatrixPanel
Подключение матрицы к ESP32, точно такое же как у автора в описании/примерах.
Матрица у меня P5(2121)3264-16S-M1. Работает точно как P3 у автора.
Не в сети
Не в сети
Не в сети
Сегодня выяснил, что моей матрице противопоказано питание выше 5В, начинает текст перекашивать даже уже при 5,2В. Лучше, питание немного ниже 5В. 4,9..5,0В - нормально.
Часы запустил в реальную работу. За 12 часов(без вайфая и ежечасной синхронизации с сервером точного времени, убежали вперёд кажется на 1..2 секунды). Через сутки, будет понятнее.
Не в сети
Новая вариация часов с градусником на DS18B20. Решена проблема конфликта прерываний DS18B20 с матрицей.
#include <stdio.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS_1 14
#include <WiFi.h>
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
#include <Fonts/FreeSansBold18pt7b.h>
OneWire oneWire_in(ONE_WIRE_BUS_1);
DallasTemperature sensor_inhouse(&oneWire_in);
String TEMP = "";
String TEMP1 = "";
P3RGB64x32MatrixPanel matrix;
#include <WiFi.h>
#include <time.h>
int boo = 1;
int a = 0;
int t = 0;
int t1 = 0;
int R = 0;
int G = 1;
int B = 0;
int TS = 1;
int t2 = 0;
float tempC;
#ifdef CREDENTIALS
const char* ssid = mySSID;
const char* password = myPASSWORD;
#else
const char* ssid = "tele2";
const char* password = "ta20242024";
#endif
const char* NTP_SERVER = "ch.pool.ntp.org";
const char* TZ_INFO = "MSK-6MSD,M3.5.0/2,M10.5.0/3"; // enter your time zone (https://remotemonitoringsystems.ca/time-zone-abbreviations.php)
tm timeinfo;
time_t now;
long unsigned lastNTPtime;
unsigned long lastEntryTime;
// Начало функции обработки кириллических символов
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;
}
// Конец функции обработки кириллических симоволов
void setup() {
Serial.begin(115200);
Serial.println("\n\nNTP Time Test\n");
WiFi.begin(ssid, password);
int counter = 0;
while (WiFi.status() != WL_CONNECTED and ++counter < 100) {
delay(200);
Serial.print ( "." );
}
if (WiFi.status() != WL_CONNECTED) {
matrix.begin();
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(3, 0, 0));
matrix.setFont();
matrix.setTextSize(1);
matrix.setCursor(0,0);
matrix.print(utf8rus("WiFi не подключен!"));
}
Serial.println("\n\nWiFi connected\n\n");
configTime(0, 0, NTP_SERVER);
// See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
setenv("TZ", TZ_INFO, 1);
if (getNTPtime(10)) { // wait up to 10sec to sync
} else {
Serial.println("Time not set");
}
showTime(&timeinfo);
lastNTPtime = time(&now);
lastEntryTime = millis();
////////////////////////matrix&ds18b20
sensor_inhouse.requestTemperatures();
float tempC = sensor_inhouse.getTempCByIndex(0);
if (tempC != DEVICE_DISCONNECTED_C)
{
Serial.println("ТЕМПЕРАТУРА 1");
Serial.print(tempC);
}
else float tempC = sensor_inhouse.getTempCByIndex(0);
Serial.print(" ");
TEMP = tempC;
matrix.begin();
}
void loop() {
// getTimeReducedTraffic(3600);
getNTPtime(10);
showTime(&timeinfo);
delay(1000);
}
bool getNTPtime(int sec) {
{
uint32_t start = millis();
do {
time(&now);
localtime_r(&now, &timeinfo);
Serial.print(".");
delay(10);
} while (((millis() - start) <= (1000 * sec)) && (timeinfo.tm_year < (2016 - 1900)));
if (timeinfo.tm_year <= (2016 - 1900)) return false; // the NTP call was not successful
Serial.print("now "); Serial.println(now);
char time_output[30];
strftime(time_output, 30, "%a %d-%m-%y %T", localtime(&now));
Serial.println(time_output);
Serial.println();
}
//////////////
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(1, 1, 0));
matrix.setFont();
matrix.setTextSize(TS);
matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
matrix.setCursor(0, 0);
matrix.print(localtime(&now));
matrix.setTextColor(matrix.color444(R, G, B));
matrix.setCursor(-130, 8);
matrix.setTextSize(2);
matrix.print(localtime(&now));
matrix.setTextSize(TS);
matrix.setCursor(-95, 24);
matrix.print(localtime(&now));
matrix.setTextColor(matrix.color444(3, 0, 0));
/////////////////////////////
if (t1>=10) {
matrix.setFont(&FreeSansBold18pt7b);
matrix.setCursor(-180, 28);
G=4;
matrix.setTextColor(matrix.color444(R, G, B));
while ( a < 37) {
matrix.fillScreen(0);
matrix.print(localtime(&now));
a=a+1;
matrix.setCursor(-180-a, 28);
}
a=0;
delay(1000);
while ( a < 34) {
matrix.fillScreen(0);
matrix.print(localtime(&now));
a=a+1;
matrix.setCursor(-217+a, 28);
}
delay(800);
a=0;
t1=0;
G=2;
}
t1=t1+1;
t2=t2+1;
if (t2>30) {
////////////////////////matrix&ds18b20
matrix.stop();
sensor_inhouse.requestTemperatures();
float tempC = sensor_inhouse.getTempCByIndex(0);
if (tempC != DEVICE_DISCONNECTED_C)
{
Serial.println("ТЕМПЕРАТУРА 1");
Serial.print(tempC);
}
else float tempC = sensor_inhouse.getTempCByIndex(0);
Serial.print(" ");
TEMP = tempC;
matrix.begin();
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(3, 0, 0));
while ( a < 90) {
a=a+1;
matrix.setFont();
matrix.setTextSize(TS);
matrix.setCursor(0,0);
matrix.print(utf8rus("температур"));
matrix.setCursor(59,0);
matrix.print(utf8rus("a"));
matrix.setTextSize(2);
matrix.setCursor(0,12);
matrix.setCursor(30-a, 12);
if (tempC >= (0)){
matrix.print("+"+TEMP+" C ");
}
if (tempC < (0)){
}
matrix.print(TEMP+" C ");
delay(80);
matrix.fillScreen(0);
}
a=0;
t2=0;
}
matrix.swapBuffer();
////////ds18b20
return true;
}
void showTime(tm *localTime) {
Serial.print(localTime->tm_mday);
Serial.print('/');
Serial.print(localTime->tm_mon + 1);
Serial.print('/');
Serial.print(localTime->tm_year - 100);
Serial.print('-');
Serial.print(localTime->tm_hour);
Serial.print(':');
Serial.print(localTime->tm_min);
Serial.print(':');
Serial.print(localTime->tm_sec);
Serial.print(" Day of Week ");
if (localTime->tm_mday = 0) localTime->tm_mday = 7;
Serial.println(localTime->tm_wday);
}
Не в сети
Немного развлекался, начал делать игру Змея с управлением с пульта ИК от телевизора.
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
// An IR detector/demodulator is connected to GPIO pin 14(D5 on a NodeMCU
// board).
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const uint16_t kRecvPin = 13;
IRrecv irrecv(kRecvPin);
decode_results results;
/////////////////
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
P3RGB64x32MatrixPanel matrix;
String irkey = "";
int x = 32;
int y = 16;
float R = 0;
float G = 0;
//float B = 1;
float a = 0;
float b = 0;
byte life = 1;
float world[63][31];
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.println();
Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
Serial.println(kRecvPin);
matrix.begin(); // setup the LED matrix
matrix.setTextColor(matrix.color444(3, 0, 0));
while (x!=63) {
while (y!=31) {
world[x][y] = 0;
y=y+1;
}
x=x+1;
}
x=0;
y=0;
a=0;
b=0;
while (a!=50) {
a=a+1;
x=random(64);
y=random(32);
world[x][y] = 1;
matrix.drawPixel(x, y, matrix.color444(R, G, 5));
// delay(50);
}
a=1;
x=32;
y=16;
}
void loop() {
////////////////////////////////
if (irrecv.decode(&results)) {
// print() & println() can't handle printing long longs. (uint64_t)
if (results.value==907442821) {//UP
a=-1;
b=0;
}
if (results.value==907426501) {//DOWN
//matrix.print("DOWN ");
a=1;
b=0;
}
if (results.value==907418341) {//LEFT
b=-1;
a=0;}
if (results.value==907475461) {//RIGHT
b=1;
a=0;}
if (results.value==907459141) {//OK
// matrix.print("OK ");
matrix.fillScreen(matrix.color444(0, 0, 0));}
if (results.value==907420381) {
R=R+1;
}
if (results.value==907432621) {
G=G+1;
}
// if (results.value==907422421) {
// B=B+1;
// }
if (results.value==907438741) ESP.restart();
serialPrintUint64(results.value, HEX);
Serial.println("");
serialPrintUint64(results.value);
Serial.println("");
irrecv.resume(); // Receive the next value
}
x=x+b;
y=y+a;
if (world[x][y] == 1) {life=life+1;}
if (world[x][y] == 3) {R=15;}
matrix.drawPixel(x, y, matrix.color444(R, 5, 0));
world[x][y]=3;
if (b==-1) {matrix.drawPixel(x+(1*life), y, matrix.color444(0, 0, 0)); world[x+(1*life)][y]=0;}
if (b==1) {matrix.drawPixel(x-(1*life), y, matrix.color444(0, 0, 0));world[x-(1*life)][y]=0;}
if (a==-1) {matrix.drawPixel(x, y+(1*life), matrix.color444(0, 0, 0));world[x][y+(1*life)]=0;}
if (a==1) {matrix.drawPixel(x, y-(1*life), matrix.color444(0, 0, 0));world[x][y-(1*life)]=0;}
delay(1000);
}
Не в сети
Игра - "Жадный змей". Управление с любого пульта ИК. Коды нажатия кнопок ИК пульта, транслируются в серийный порт.
Фотоприёмник ИК, подключен к порту 13.
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
const uint16_t kRecvPin = 13;
IRrecv irrecv(kRecvPin);
decode_results results;
/////////////////
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
P3RGB64x32MatrixPanel matrix;
String irkey = "";
int x = 32;
int y = 16;
float R = 0;
float G = 0;
//float B = 1;
float a = 0;
float b = 0;
byte life = 1;
float world[64][32];
// Начало функции обработки кириллических символов
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;
}
// Конец функции обработки кириллических симоволов
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.println();
Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
Serial.println(kRecvPin);
matrix.begin(); // setup the LED matrix
// matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
while (a!=26) {
matrix.setTextColor(matrix.color444(2, 2, 2));
matrix.setCursor(0,a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,a);
matrix.print(utf8rus("ЗМЕЙ"));
matrix.setTextColor(matrix.color444(0, 0, 0));
delay(50);
matrix.setCursor(0,a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,a);
matrix.print(utf8rus("ЗМЕЙ"));
a=a+1;
}
a=0;
while (a!=16) {
matrix.setTextColor(matrix.color444(2, 2, 2));
matrix.setCursor(0,26-a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,26-a);
matrix.print(utf8rus("ЗМЕЙ"));
matrix.setTextColor(matrix.color444(0, 0, 0));
delay(50);
matrix.setCursor(0,26-a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,26-a);
matrix.print(utf8rus("ЗМЕЙ"));
a=a+1;
}
matrix.setTextColor(matrix.color444(2, 2, 2));
matrix.setCursor(0,26-a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,26-a);
matrix.print(utf8rus("ЗМЕЙ"));
delay(5000);
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(3, 0, 0));
while (x!=63) {
while (y!=31) {
world[x][y] = 0;
y=y+1;
}
x=x+1;
}
x=0;
y=0;
a=0;
b=0;
while (a!=50) {
a=a+1;
x=random(64);
y=random(32);
world[x][y] = 1;
matrix.drawPixel(x, y, matrix.color444(R, G, 5));
// delay(50);
}
a=0;
b=1;
x=32;
y=16;
}
void loop() {
////////////////////////////////
if (irrecv.decode(&results)) {
// print() & println() can't handle printing long longs. (uint64_t)
if (results.value==907442821) {//UP
a=-1;
b=0;
}
if (results.value==907426501) {//DOWN
//matrix.print("DOWN ");
a=1;
b=0;
}
if (results.value==907418341) {//LEFT
b=-1;
a=0;}
if (results.value==907475461) {//RIGHT
b=1;
a=0;}
// if (results.value==907459141) {//OK
// matrix.print("OK ");
//matrix.fillScreen(matrix.color444(0, 0, 0));}
if (results.value==907420381) {
R=R+1;
}
if (results.value==907432621) {
G=G+1;
}
// if (results.value==907422421) {
// B=B+1;
// }
if (results.value==907438741) ESP.restart();
Serial.println("Нажата кнопка ИК пульта с кодом - ");
serialPrintUint64(results.value);
Serial.println("");
irrecv.resume(); // Receive the next value
}
x=x+b;
y=y+a;
if (world[x][y] == 1) {life=life+1;}
if (world[x][y] == 3 or x<0 or x>64 or y<0 or y>32) {
matrix.fillScreen(1);
delay(500);
matrix.fillScreen(0);
delay(500);
matrix.fillScreen(1);
delay(500);
matrix.fillScreen(0);
delay(500);
matrix.fillScreen(1);
delay(500);
ESP.restart();
}
matrix.drawPixel(x, y, matrix.color444(0, 2, 0));
world[x][y]=3;
if (b==-1) {matrix.drawPixel(x+(1*life), y, matrix.color444(0, 0, 0)); world[x+(1*life)][y]=0;}
if (b==1) {matrix.drawPixel(x-(1*life), y, matrix.color444(0, 0, 0));world[x-(1*life)][y]=0;}
if (a==-1) {matrix.drawPixel(x, y+(1*life), matrix.color444(0, 0, 0));world[x][y+(1*life)]=0;}
if (a==1) {matrix.drawPixel(x, y-(1*life), matrix.color444(0, 0, 0));world[x][y-(1*life)]=0;}
delay(500);
}
Не в сети
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
const uint16_t kRecvPin = 13;
IRrecv irrecv(kRecvPin);
decode_results results;
/////////////////
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
P3RGB64x32MatrixPanel matrix;
String irkey = "";
int x = 32;
int y = 16;
float R = 0;
float G = 0;
//float B = 1;
float a = 0;
float b = 0;
byte live = 1;
byte life = 1;
byte level=1;
byte levelnext=1;
float world[64][32]={0};
// Начало функции обработки кириллических символов
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;
}
// Конец функции обработки кириллических симоволов
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
while (!Serial) // Wait for the serial connection to be establised.
delay(50);
Serial.println();
Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
Serial.println(kRecvPin);
matrix.begin(); // setup the LED matrix
// matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
}
void loop() {
///////ЗАСТАВКА////////
x=0;
y=0;
a=0;
b=0;
levelnext=1;
life=1;
live=level;
while (a!=26) {
matrix.setTextColor(matrix.color444(2, 2, 2));
matrix.setCursor(0,a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,a);
matrix.print(utf8rus("ЗМЕЙ"));
matrix.setTextColor(matrix.color444(0, 0, 0));
delay(50);
matrix.setCursor(0,a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,a);
matrix.print(utf8rus("ЗМЕЙ"));
a=a+1;
}
a=0;
while (a!=16) {
matrix.setTextColor(matrix.color444(2, 2, 2));
matrix.setCursor(0,26-a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,26-a);
matrix.print(utf8rus("ЗМЕЙ"));
matrix.setTextColor(matrix.color444(0, 0, 0));
delay(50);
matrix.setCursor(0,26-a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,26-a);
matrix.print(utf8rus("ЗМЕЙ"));
a=a+1;
}
matrix.setTextColor(matrix.color444(2, 2, 2));
matrix.setCursor(0,26-a);
matrix.print(utf8rus("ЖАДНЫЙ"));
matrix.setCursor(39,26-a);
matrix.print(utf8rus("ЗМЕЙ"));
matrix.setCursor(6,18);
matrix.print(utf8rus("Уровень ")+level);
delay(2000);
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(3, 0, 0));
//x=0;
// y=0;
// a=0;
// b=0;
//while (x!=64) {
// while (y!=32) {
// world[x][y] = 0;
// y=y+1;
// }
//x=x+1;
//}
world[64][32]={0};
x=0;
y=0;
a=0;
b=0;
while (a!=level*3) {
a=a+1;
x=random(63);
y=random(31);
world[x][y] = 1;
matrix.drawPixel(x, y, matrix.color444(0, 0, 5));
// delay(50);
}
a=0;
b=1;
x=32;
y=16;
//////////////////////////////// тело игры////
while (levelnext!=0) {
if (irrecv.decode(&results)) {
// print() & println() can't handle printing long longs. (uint64_t)
if (results.value==907442821) {//UP
a=-1;
b=0;
}
if (results.value==907426501) {//DOWN
//matrix.print("DOWN ");
a=1;
b=0;
}
if (results.value==907418341) {//LEFT
b=-1;
a=0;}
if (results.value==907475461) {//RIGHT
b=1;
a=0;}
// if (results.value==907459141) {//OK
// matrix.print("OK ");
//matrix.fillScreen(matrix.color444(0, 0, 0));}
if (results.value==907420381) {
R=R+1;
}
if (results.value==907432621) {
G=G+1;
}
// if (results.value==907422421) {
// B=B+1;
// }
// if (results.value==907438741) ESP.restart();//POWER
Serial.println("Нажата кнопка ИК пульта с кодом - ");
serialPrintUint64(results.value);
Serial.println("");
irrecv.resume(); // Receive the next value
}
x=x+b;
y=y+a;
if (world[x][y] == 1) {life=life+1;}
if (life==level*3+1) {
levelnext=0; level=level+1; life=1;
}
//if (world[x][y] == 3 or x<0 or x>64 or y<0 or y>32) {
// live=live-1; levelnext=0;
//matrix.setCursor(0,0);
// matrix.setTextColor(matrix.color444(1, 0, 0));
// matrix.print(live);
//delay(2000);
//}
if (world[x][y] == 3 or x<0 or x>64 or y<0 or y>32) {level=level-1; levelnext=0; world[64][32]={0};
}
if ((world[x][y] == 3 or x<0 or x>64 or y<0 or y>32) and (level==0)) {
matrix.fillScreen(1);
delay(500);
matrix.fillScreen(0);
delay(500);
matrix.fillScreen(1);
delay(500);
matrix.fillScreen(0);
delay(500);
matrix.fillScreen(1);
delay(500);
ESP.restart();
}
matrix.drawPixel(x, y, matrix.color444(0, 2, 0));
world[x][y]=3;
if (b==-1) {matrix.drawPixel(x+(1*life), y, matrix.color444(0, 0, 0)); world[x+(1*life)][y]=0;}
if (b==1) {matrix.drawPixel(x-(1*life), y, matrix.color444(0, 0, 0));world[x-(1*life)][y]=0;}
if (a==-1) {matrix.drawPixel(x, y+(1*life), matrix.color444(0, 0, 0));world[x][y+(1*life)]=0;}
if (a==1) {matrix.drawPixel(x, y-(1*life), matrix.color444(0, 0, 0));world[x][y-(1*life)]=0;}
delay(500-level*100);
}
}
Не в сети
Эмуляция жизни бактерий. LIFE.
https://www.youtube.com/watch?v=hrMxTFuVMks
https://www.youtube.com/watch?v=KFpID7ixaMY
#include <Adafruit_GFX.h> // Core graphics library
#include <P3RGB64x32MatrixPanel.h>
P3RGB64x32MatrixPanel matrix;
byte world[64][64][2];
long density = 20;
int polltime;
void setup() {
matrix.begin();
randomSeed(analogRead(0));
randomscreen();
}
void loop() {
if (millis()-polltime >=50) { displayoutput(); polltime=millis();};
}
int neighbours(int x, int y) {
return
world[(x + 1) % 64][ y ] [0] +
world[ x ][ (y + 1) % 32] [0] +
world[(x + 64 - 1) % 64][ y ] [0] +
world[ x ][ (y + 32 - 1) % 32] [0] +
world[(x + 1) % 64][ (y + 1) % 32] [0] +
world[(x + 64 - 1) % 64][ (y + 1) % 32] [0] +
world[(x + 64 - 1) % 64][ (y + 32 - 1) % 32] [0] +
world[(x + 1) % 64 ][ (y + 32 - 1) % 32] [0];
}
void randomscreen() {
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 64; x++) {
if (random(50) < density) {world[x][y][0] = 1; }
else {world[x][y][0] = 0;}
world[x][x][1] = 0;
}
}
}
void displayoutput(){
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 64; x++) {
// Default is for cell to stay the same
world[x][y][1] = world[x][y][0];
int count = neighbours(x, y);
if (count == 3 && world[x][y][0] == 0) { world[x][y][1] = 1;matrix.drawPixel(x, y, matrix.color444(0,1,0)); } //new cell
if ((count < 2 || count > 3) && world[x][y][0] == 1) { world[x][y][1] = 0;matrix.drawPixel(x, y, matrix.color444(0,0,0)); } //cell dies
}
}
// swap next generation into place
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 64; x++) {
world[x][y][0] = world[x][y][1];
}
}
}
Не в сети
Очередная моя переделка часов NTP. Исходник был взят тут.
https://github.com/pisuke/Heltec_OLED_NPT_Clock
Проверил на модуле WiFi 32 LORA. Отлично работает программа. Перенёс это всё безобразие на ESP32 Devkit v1 + RGB матрица 64/32 P5.
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSansBold24pt7b.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>
P3RGB64x32MatrixPanel matrix;
// WiFi configuration
const char ssid[] = "tele2"; // your network SSID (name)
const 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
int a = 0;
// Начало функции обработки кириллических символов
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;
}
// Конец функции обработки кириллических симоволов
void setup()
{
Serial.begin(115200);
while (!Serial) ; // Needed for Leonardo only
delay(250);
Serial.println("\nESP32 NTP clock");
// 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"
// int week_number = jsonDoc["week_number"]; // 30
// convert UTC offset to signed float
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);
pftime::configTime(utc_offset_float * 3600, 0, ntpServerName);
}
void loop()
{
if (now() != prevDisplay) { //update the display only if time has changed
// matrix.begin();//СТАРТ МАТРИЦЫ
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);
// Print the time to serial
Serial.println(dateString + " | " + timeString + " " + timeZoneAbbreviation + " " + timeZone_str);
if (tm->tm_sec==0){
//ПЕЧАТЬ ДАННЫХ НА МАТРИЦЕ
matrix.begin();//СТАРТ МАТРИЦЫ
matrix.setTextColor(matrix.color444(0, 1, 0));//ЦВЕТ ТЕКСТА RGB ОТ 1 ДО 15
matrix.setFont(&FreeSansBold12pt7b);
// matrix.setFont();
matrix.setTextSize(0);
matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
//matrix.fillScreen(0);
// matrix.setFont();
// matrix.setCursor(2, 17);
// matrix.print(utf8rus("Русский алфавит"));
// delay(3000);
matrix.setFont(&FreeSansBold12pt7b);
matrix.fillScreen(0);
matrix.setCursor(2, 17);
matrix.print(timeString);
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 3));
matrix.print(dateString); }
if (tm->tm_sec==30){
matrix.setTextColor(matrix.color444(0, 3, 0));//трансляция бегущей строки
matrix.setFont(&FreeSansBold24pt7b);
while ( a < 55) {
matrix.fillScreen(0);
matrix.setCursor(0-a, 31);
matrix.print(timeString);
a=a+1;
delay(25);
}
delay(1000);
while ( a>= 0) {
matrix.fillScreen(0);
matrix.setCursor(0-a, 31);
matrix.print(timeString);
a=a-1;
delay(25);
}
delay(1000);
matrix.setTextColor(matrix.color444(0, 1, 0));//ЦВЕТ ТЕКСТА RGB ОТ 0 ДО 15
matrix.setFont(&FreeSansBold12pt7b);
matrix.setTextSize(0);
matrix.fillScreen(0);
matrix.setCursor(2, 17);
matrix.print(timeString);
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 3));
matrix.print(dateString);
}
}
}
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) {
Serial.print(".");
delay(500);
}
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);
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);
// sprintf(time_string, "%02d:%02d:%02d",
// tm->tm_hour,
// tm->tm_min,
// tm->tm_sec);
Serial.println(tm->tm_sec);
return time_string;
}
#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). Больше года, пытался такого результата добиться. Сегодня, сделал! И с русскими шрифтами, всё как я мечтал.
Не в сети
Не в сети
Только успел порадоваться автоматическому выбору временной зоны, как схватил 01.01.1970 | 03:01 MSK Europe/Moscow
Не в сети
А так красиво всё начиналось! Автоматом определялась зона Новосибирска, при подключении к телефону....
Не в сети
Перезагрузил телефон, снова вернулось местное время автоматом. Нужно тестировать.
Не в сети
Скорее всего, проглючивает иногда сервер времени "pool.ntp.org". Сервак любительский. Да и нужен он, только для получения эталонного времени при старте. ESP32, с новыми библиотеками времени, может шлёпать довольно точно месяцами, вообще без коррекции через сеть.
Не в сети
Не в сети
Не в сети
#include <TM1637TinyDisplay.h>
#define CLK 5
#define DIO 19
TM1637TinyDisplay display(CLK, DIO);
#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSans24pt7b.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 14
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
P3RGB64x32MatrixPanel matrix;
// WiFi configuration
const char ssid[] = "tele2"; // your network SSID (name)
const 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
int a = 0;
int tempC = 0;
// Начало функции обработки кириллических символов
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;
}
// Конец функции обработки кириллических симоволов
void setup()
{
Serial.begin(115200);
//TM1637//
display.setBrightness(BRIGHT_7);
////////////////
sensors.begin();
sensors.requestTemperatures();
tempC = sensors.getTempCByIndex(0);
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
while (!Serial) ; // Needed for Leonardo only
delay(250);
Serial.println("\nESP32 NTP clock");
// 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"
// int week_number = jsonDoc["week_number"]; // 30
// convert UTC offset to signed float
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);
pftime::configTime(utc_offset_float * 3600, 0, ntpServerName);
}
void loop()
{
if (now() != prevDisplay) { //update the display only if time has changed
// matrix.begin();//СТАРТ МАТРИЦЫ
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);
// Print the time to serial
Serial.println(dateString + " | " + timeString + " " + timeZoneAbbreviation + " " + timeZone_str);
if (tm->tm_sec==0){
display.clear();
// display.showNumber(((tm->tm_hour*100)+tm->tm_min), 2);
display.showNumberDec(((tm->tm_hour*100)+tm->tm_min), (0x80 >> 1), true);
matrix.fillScreen(0);
matrix.stop();
sensors.requestTemperatures();
tempC = sensors.getTempCByIndex(0);
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
matrix.begin();
matrix.setTextColor(matrix.color444(0, 15, 0));//ЦВЕТ ТЕКСТА RGB ОТ 1 ДО 15
matrix.setFont(&FreeSans12pt7b);
matrix.setTextSize(0);
matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
matrix.fillScreen(0);
matrix.setCursor(3, 16);
matrix.print(timeString);
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 15));
matrix.print(dateString);
matrix.setTextColor(matrix.color444(15, 15, 0));
matrix.setCursor(2, 18);
matrix.print(utf8rus("Темп."));
if (tempC>0) matrix.print("+");
matrix.print(tempC);
matrix.print("`C");
}
/////////////////////////15sec/////////////////////////////
if (tm->tm_sec==15){
///////////////////////// Вывод температуры на дисплей TM1637
display.clear();
display.showNumber(tempC*10);
display.showString("\xB0", 1, 3);
a=0;
while ( a < 25) {
matrix.setTextColor(matrix.color444(0, 15, 0));
matrix.setFont(&FreeSans18pt7b);
matrix.fillScreen(0);
matrix.setCursor(0-a, 24);
matrix.print(timeString);
a=a+1;
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 15));
matrix.print(dateString);
delay(20);
}
delay(2000);
while ( a>= 0) {
matrix.setTextColor(matrix.color444(0, 15, 0));
matrix.setFont(&FreeSans18pt7b);
matrix.fillScreen(0);
matrix.setCursor(0-a, 24);
matrix.print(timeString);
a=a-1;
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 15));
matrix.print(dateString);
delay(20);
}
delay(2000);
a=0;
matrix.setTextColor(matrix.color444(0, 15, 0));//ЦВЕТ ТЕКСТА RGB ОТ 1 ДО 15
matrix.setFont(&FreeSans12pt7b);
matrix.setTextSize(0);
matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
matrix.fillScreen(0);
matrix.setCursor(3, 17);
matrix.print(timeString);
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 15));
matrix.print(dateString);
matrix.setTextColor(matrix.color444(15, 15, 0));
matrix.setCursor(2, 18);
matrix.print(utf8rus("Темп."));
if (tempC>0) matrix.print("+");
matrix.print(tempC);
matrix.print("`C");
}
/////////////////////////end 15sec/////////////////////////////
/////////////////////////45sec/////////////////////////////
if (tm->tm_sec==45){
a=0;
matrix.setFont(0);
matrix.setTextSize(4);
matrix.setTextColor(matrix.color444(15, 15, 15));
while ( a < 550) {
matrix.fillScreen(0);
matrix.setCursor(0-a, 2);
matrix.print(utf8rus("ТЕМПЕРАТУРА ВОЗДУХА "));
if (tempC>0) matrix.print("+");
matrix.print(tempC);
matrix.print("`C");
a=a+1;
delay(6);
}
delay(500);
a=0;
matrix.setTextColor(matrix.color444(0, 15, 0));//ЦВЕТ ТЕКСТА RGB ОТ 1 ДО 15
matrix.setFont(&FreeSans12pt7b);
matrix.setTextSize(0);
matrix.setTextWrap(false);//ЗАПРЕТ ПЕРЕНОСА СТРОКИ
matrix.fillScreen(0);
matrix.setCursor(3, 17);
matrix.print(timeString);
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 15));
matrix.print(dateString);
matrix.setTextColor(matrix.color444(15, 15, 0));
matrix.setCursor(2, 18);
matrix.print(utf8rus("Темп."));
if (tempC>0) matrix.print("+");
matrix.print(tempC);
matrix.print("`C");
}
/////////////////////////end 45sec/////////////////////////////
if (tm->tm_sec==30){
display.clear();
display.showNumberDec(((tm->tm_hour*100)+tm->tm_min), (0x80 >> 1), true);
matrix.setTextColor(matrix.color444(0, 15, 0));//трансляция бегущей строки
matrix.setFont(&FreeSans24pt7b);
while ( a < 55) {
matrix.fillScreen(0);
matrix.setCursor(0-a, 31);
matrix.print(timeString);
a=a+1;
delay(15);
}
delay(2000);
while ( a>= 0) {
matrix.fillScreen(0);
matrix.setCursor(0-a, 31);
matrix.print(timeString);
a=a-1;
delay(15);
}
delay(2000);
matrix.fillScreen(0);
matrix.setTextColor(matrix.color444(0, 15, 0));//ЦВЕТ ТЕКСТА RGB ОТ 0 ДО 15
matrix.setFont(&FreeSans12pt7b);
matrix.setTextSize(0);
matrix.setCursor(3, 17);
matrix.print(timeString);
matrix.setCursor(2, 31);
matrix.setFont(0);
matrix.setTextColor(matrix.color444(0, 0, 15));
matrix.print(dateString);
matrix.setTextColor(matrix.color444(15, 15, 0));
matrix.setCursor(2, 18);
matrix.print(utf8rus("Темп."));
if (tempC>0) matrix.print("+");
matrix.print(tempC);
matrix.print("`C");
}
}
}
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) {
Serial.print(".");
delay(500);
}
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);
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);
return time_string;
}
#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;
}
/* 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
Не в сети
Не в сети
Сделал этому железу апгрейд. На днях, возможно выложу новый скетч.
Не в сети
P3RGB64x32MatrixPanel.h не обновлялась уже давно.
Думаю переделать эту матрицу на PxMatrix.h
На двух матрицах 64x64, у меня эта библиотека получше работает.
Не в сети
Сколько я не мучился, библиотека P3RGB64x32MatrixPanel.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
Схема соединения входного гнезда матрицы(PI) и выходного гнезда матрицы (PO)
PI PO
R2 R1
G1 R2
G2 G1
B1 G2
B2 B1
Не в сети
Не в сети
Не в сети