1

Тема: ESP32 ретро часы (разработка)

Основная статья - http://rcl-radio.ru/?p=97415

Источник +180В

http://forum.rcl-radio.ru/uploads/images/2021/03/2becd857450ad23b9a41ebe899673b35.png

http://forum.rcl-radio.ru/uploads/images/2021/03/5fc04ce4fc443b3856a51ac01b1bb21f.png

http://forum.rcl-radio.ru/uploads/images/2021/03/cef3e7c22ca2dac25da6494f987ed4f0.jpeg

ESP32
http://forum.rcl-radio.ru/uploads/images/2021/03/7c76d93afda31fb04e2f44093cddf8ba.jpg
ИН-18
http://forum.rcl-radio.ru/uploads/images/2021/03/de589a45bc54e934532e87a668da14ed.jpg

void setup(){
  ledcSetup(0, 20000, 6);// канал 0, частота 20000гц, 6 бит
  ledcAttachPin(15, 0);// GPIO15, канал 0
  ledcWrite(0, 31); // шим 50% (6 бит = 63)
}

void loop(){
  

}

2

Re: ESP32 ретро часы (разработка)

ТАЙМЕР

#include "esp_system.h"
  hw_timer_t *timer = NULL;

void IRAM_ATTR oneTimer() {
 // CODE //
}  

void setup(){  
  Serial.begin(9600);
//////// PWM ///////////////  
  ledcSetup(0, 20000, 6);
  ledcAttachPin(15, 0);
  ledcWrite(0, 31);
//////// TIMER1 ////////////  
  timer = timerBegin(0, 80, true);                  //timer 0, div 80
  timerAttachInterrupt(timer, oneTimer, true);  //attach callback
  timerAlarmWrite(timer, 500000, true); //set time in us
  timerAlarmEnable(timer);   
}

void loop(){
  
}

3

Re: ESP32 ретро часы (разработка)

Данный контент доступен только зарегистрированным пользователям.

4

Re: ESP32 ретро часы (разработка)

Схема

http://forum.rcl-radio.ru/uploads/images/2021/03/ea102567677ad942d81f914f7f7445b1.gif

5

Re: ESP32 ретро часы (разработка)

тест

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13


#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include "esp_system.h"
  const char* ssid     = "Redmi Note 3";
  const char* password = "32481975";
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  int ss,mm,hh,i,an,segm;
  byte a[6];
  unsigned long times;
  hw_timer_t *timer = NULL;

void IRAM_ATTR oneTimer() {
    switch(i){
    case 0: segm=a[0]; an=0; anod(); segment();break;
    case 1: segm=a[1]; an=1; anod(); segment();break;
    case 2: segm=a[2]; an=2; anod(); segment();break;
    case 3: segm=a[3]; an=3; anod(); segment();break;
    case 4: segm=a[4]; an=4; anod(); segment();break;
    case 5: segm=a[5]; an=5; anod(); segment();break;}i++;if(i>5){i=0;}
}  

void setup(){  
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED ){delay (10);Serial.print ( "." );timeClient.begin();}
//////// PWM /////////////// 
  pinMode(15,OUTPUT); 
  ledcSetup(1, 20000, 8); // 20000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 1);   // D15 / cannel 1
  ledcWrite(1, 200);       // 8bit=255, PWM50%=127 / cannel 1
///////// TIMER ///////////  
  timer = timerBegin(0, 80, true);  //timer 0, div 80 === 1 uS
  timerAttachInterrupt(timer, oneTimer, true);  //attach callback
  timerAlarmWrite(timer, 2000, true); // 2mS
  timerAlarmEnable(timer); // timer start
//////////////////////////
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT); 
 pinMode(IN4,OUTPUT); 
 pinMode(IN5,OUTPUT); 
 pinMode(IN6,OUTPUT); 
 pinMode(ID1,OUTPUT); 
 pinMode(ID2,OUTPUT); 
 pinMode(ID4,OUTPUT); 
 pinMode(ID8,OUTPUT);   
   
}

void loop(){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
  }
  a[0]=hh/10;
  a[1]=hh%10;
  a[2]=mm/10;
  a[3]=mm%10;
  a[4]=ss/10;
  a[5]=ss%10;
//////////////////////////////////////////////////////   
   

}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b0110
  }}
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;   
  }}
  

6

Re: ESP32 ретро часы (разработка)

http://forum.rcl-radio.ru/uploads/images/2021/03/ec586ff8e6449cd1a9e951a646d3a1fb.png

http://forum.rcl-radio.ru/uploads/images/2021/03/e9f92dc240035dcf2996560e19c7f38a.png

7

Re: ESP32 ретро часы (разработка)

Тестовый запуск

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13


#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include "esp_system.h"
  const char* ssid     = "Keenetic-9009";
  const char* password = "32481975";
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  int ss,mm,hh,i,an,segm,brig;
  byte a[6];
  unsigned long times, sum;
  hw_timer_t *timer = NULL;

void IRAM_ATTR oneTimer() {
    switch(i){
    case 0: segm=10;an=10;anod();segment();delayMicroseconds(1500);segm=a[0]; an=0; anod();segment(); break;
    case 1: segm=10;an=10;anod();segment();delayMicroseconds(1500);segm=a[1]; an=1; segment();anod(); break;
    case 2: segm=10;an=10;anod();segment();delayMicroseconds(1500);segm=a[2]; an=2; segment();anod(); break;
    case 3: segm=10;an=10;anod();segment();delayMicroseconds(1500);segm=a[3]; an=3; segment();anod(); break;
    case 4: segm=10;an=10;anod();segment();delayMicroseconds(1500);segm=a[4]; an=4; segment();anod(); break;
    case 5: segm=10;an=10;anod();segment();delayMicroseconds(1500);segm=a[5]; an=5; segment();anod(); break;}i++;if(i>5){i=0;}
}  

void setup(){  
//////// PWM ///////////////  
  pinMode(15,OUTPUT); 
  digitalWrite(15,HIGH);
///////////////////////////
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED ){delay (10);Serial.print ( "." );timeClient.begin();}
  ledcSetup(1, 25000, 8); // 20000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 1);   // D15 / cannel 1
  ledcWrite(1, 150);  // 200 мин 150 макс     // 8bit=255, invert PWM50%=127 / cannel 1
///////// TIMER ///////////  
  timer = timerBegin(0, 80, true);  //timer 0, div 80 === 1 uS
  timerAttachInterrupt(timer, oneTimer, true);  //attach callback
  timerAlarmWrite(timer, 3000, true); // 2mS
  timerAlarmEnable(timer); // timer start
//////////////////////////
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT); 
 pinMode(IN4,OUTPUT); 
 pinMode(IN5,OUTPUT); 
 pinMode(IN6,OUTPUT); 
 pinMode(ID1,OUTPUT); 
 pinMode(ID2,OUTPUT); 
 pinMode(ID4,OUTPUT); 
 pinMode(ID8,OUTPUT);   
}

void loop(){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
  }
sum = mm*100+ss;
///////// ///////////////  
 if(mm==30&&ss<10){
  switch(ss){
    case 0: sum=0000;break;
    case 1: sum=1111;break;
    case 2: sum=2222;break;
    case 3: sum=3333;break;
    case 4: sum=4444;break;
    case 5: sum=5555;break;
    case 6: sum=6666;break;
    case 7: sum=7777;break;
    case 8: sum=8888;break;
    case 9: sum=9999;break;}}
  
  a[0]=sum/1000;
  a[1]=sum/100%10;
  a[2]=sum/10%10;
  a[3]=sum%10;
  a[4]=hh/10;
  a[5]=hh%10;


 /////////////////////////   
  if(hh>23&&hh<6){ ledcWrite(1, 200); }
//////////////////////////////////////////////////////   
   

}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b0110
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

Используются только секунды и минуты

http://forum.rcl-radio.ru/uploads/images/2021/03/99ecbf11b2ac7b5c0d76a7df806e6e65.png

Источник питания
Входное напряжение 12 В, выходное 5 В, 190 В
http://forum.rcl-radio.ru/uploads/images/2021/03/a060f0483d36c587088ffa6d841964d2.png

ИН-14 ИН-18
http://forum.rcl-radio.ru/uploads/images/2021/03/3d6adb4259f566cd179ba9eb0f3f13d1.png

8

Re: ESP32 ретро часы (разработка)

http://forum.rcl-radio.ru/uploads/images/2021/03/8fa1a3eac64c016fa4d246ee93776ea1.png

http://forum.rcl-radio.ru/uploads/images/2021/03/60cfd13672d5e0449993d2bfa4d4113f.png


#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"
#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif
const char *ssid = APSSID;
const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int ss,mm,hh,i,an,segm,brignes,brignes_low;
  byte a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int w,ip1,ip2,ip3,ip4,utc;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
  portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
  case 0: segm=10;an=10;segment();anod();delayMicroseconds(1400);segm=a[0]; an=0; segment();anod();delayMicroseconds(1400);segm=10;an=10;segment();anod();delayMicroseconds(200);break;
  case 1: segm=10;an=10;segment();anod();delayMicroseconds(1400);segm=a[1]; an=1; segment();anod();delayMicroseconds(1400);segm=10;an=10;segment();anod();delayMicroseconds(200);break;
  case 2: segm=10;an=10;segment();anod();delayMicroseconds(1400);segm=a[2]; an=2; segment();anod();delayMicroseconds(1400);segm=10;an=10;segment();anod();delayMicroseconds(200);break;
  case 3: segm=10;an=10;segment();anod();delayMicroseconds(1400);segm=a[3]; an=3; segment();anod();delayMicroseconds(1400);segm=10;an=10;segment();anod();delayMicroseconds(200);break;
  case 4: segm=10;an=10;segment();anod();delayMicroseconds(1400);segm=a[4]; an=4; segment();anod();delayMicroseconds(1400);segm=10;an=10;segment();anod();delayMicroseconds(200);break;
  case 5: segm=10;an=10;segment();anod();delayMicroseconds(1400);segm=a[5]; an=5; segment();anod();delayMicroseconds(1400);segm=10;an=10;segment();anod();delayMicroseconds(200);break;
    }
    i++;if(i>5){i=0;}
  portEXIT_CRITICAL_ISR(&timerMux);
  xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
   timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23
  digitalWrite(15,HIGH);

  Serial.begin(9600);

/// точка доступа
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
  }
  else{
   // Режим STATION
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
 if(len_pass > 64) len_pass = 0;
///////////////////////////
      unsigned char* buf_ssid = new unsigned char[32];
      unsigned char* buf_pass = new unsigned char[64];
      for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
      buf_ssid[len_ssid] = '\x0';
      const char *ssid  = (const char*)buf_ssid;
      for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
      const char *pass  = (const char*)buf_pass;
      buf_pass[len_pass] = '\x0';
      delay(2000);
      Serial.print("SSID: ");
      Serial.print(ssid);
      Serial.print("   ");
      Serial.print("Password: ");
      Serial.println(pass);
       
      WiFi.begin(ssid, pass);
      while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
      Serial.println();
      Serial.print("Connected to ");
      Serial.println(ssid);
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());

       ip1 = WiFi.localIP()[0];
       ip2 = WiFi.localIP()[1];
       ip3 = WiFi.localIP()[2];
       ip4 = WiFi.localIP()[3];
      
      server.begin();
      server.on("/", web);
      server.on("/reset", web0);
      
  }
  
////////////////////////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  



  ////////////////////////////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer);    

  

 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT); 
 pinMode(IN4,OUTPUT); 
 pinMode(IN5,OUTPUT); 
 pinMode(IN6,OUTPUT); 
 pinMode(ID1,OUTPUT); 
 pinMode(ID2,OUTPUT); 
 pinMode(ID4,OUTPUT); 
 pinMode(ID8,OUTPUT); 
 timeClient.setTimeOffset(utc*1800); 
 times1=millis();    
}



void loop(){
  delay(1000);
  server.handleClient();
   if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
 ///// brightness  
 // hh = 0;
   if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low); }else { ledcWrite(2, 255-brignes);}
  }
  sum = mm*100+ss;
  
///////// ///////////////  
 if(mm==30&&ss<10){
  switch(ss){
    case 0: sum=0000;break;
    case 1: sum=1111;break;
    case 2: sum=2222;break;
    case 3: sum=3333;break;
    case 4: sum=4444;break;
    case 5: sum=5555;break;
    case 6: sum=6666;break;
    case 7: sum=7777;break;
    case 8: sum=8888;break;
    case 9: sum=9999;break;}}
  
  a[0]=sum/1000;
  a[1]=sum/100%10;
  a[2]=sum/10%10;
  a[3]=sum%10;
  a[4]=hh/10;
  a[5]=hh%10;


 if(millis()-times1<=2000){a[0]=0;a[1]=ip1/100;a[2]=ip1/10%10;a[3]=ip1%10;}
 if(millis()-times1>2000&&millis()-times1<=4000){a[0]=0;a[1]=ip2/100;a[2]=ip2/10%10;a[3]=ip2%10;}
 if(millis()-times1>4000&&millis()-times1<=6000){a[0]=0;a[1]=ip3/100;a[2]=ip3/10%10;a[3]=ip3%10;}
 if(millis()-times1>6000&&millis()-times1<=8000){a[0]=0;a[1]=ip4/100;a[2]=ip4/10%10;a[3]=ip4%10;}

    

   }   

  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          webPage +="<td><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td><center><big>Текущее время: ";
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<tr><td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
  
    if (server.args() > 0 ) {
    for ( uint8_t i = 0; i < server.args(); i++ ) {
      if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
      if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
      if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
   //   if (server.argName(i) == "cv1"){cv1 = server.arg(i).toInt();}
      }
      Serial.println("Save");
      if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
      if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
        
      EEPROM.commit();
      EEPROM.end(); 
      
      EEPROM.begin(512);
      brignes = EEPROM.read(200); 
      utc = EEPROM.read(201);
      brignes_low = EEPROM.read(202); 
      timeClient.setTimeOffset(utc*1800);
      if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low); }else { ledcWrite(2, 255-brignes);}
      }}  

void handleRoot() { 
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
}      

void handleOk(){
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);
 
  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
      EEPROM.write(i, buf[i]);
      
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
      EEPROM.write(i + 32, buf[i]);
      
      EEPROM.commit();
      EEPROM.end(); 
   
    ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D1 и перезагрузите ESP32</p><br>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
    }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
}


void web0() { 
          timerAlarmWrite(timer, 35, false);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
          server.send (200, "text/html", str0);
          sumbit();
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}   

9

Re: ESP32 ретро часы (разработка)

http://forum.rcl-radio.ru/uploads/images/2021/03/957d779a7acb2b3548327f77853d6a09.png

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night;
  byte a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int w,ip1,ip2,ip3,ip4,utc;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[0]; an=0; segment();anod();break;
     case 1: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[1]; an=1; segment();anod();break;
     case 2: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[2]; an=2; segment();anod();break;
     case 3: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[3]; an=3; segment();anod();break;
     case 4: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[4]; an=4; segment();anod();break;
     case 5: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[5]; an=5; segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23 
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
   ip1 = WiFi.localIP()[0];
   ip2 = WiFi.localIP()[1];
   ip3 = WiFi.localIP()[2];
   ip4 = WiFi.localIP()[3];
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM /////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 30, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  delay(1000);
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*100+mm;
///////// ///////////////  
 if(mm==30&&ss<10){
  switch(ss){
    case 0: sum=0000;break;
    case 1: sum=1111;break;
    case 2: sum=2222;break;
    case 3: sum=3333;break;
    case 4: sum=4444;break;
    case 5: sum=5555;break;
    case 6: sum=6666;break;
    case 7: sum=7777;break;
    case 8: sum=8888;break;
    case 9: sum=9999;break;}}
  
  a[0]=sum/1000;
  a[1]=sum/100%10;
  a[2]=sum/10%10;
  a[3]=sum%10;
  a[4]=hh/10;
  a[5]=hh%10;

 if(w<4){
 if(w==0){a[0]=0;a[1]=ip1/100;a[2]=ip1/10%10;a[3]=ip1%10;delay(2000);w++;}
 if(w==1){a[0]=0;a[1]=ip2/100;a[2]=ip2/10%10;a[3]=ip2%10;delay(2000);w++;}
 if(w==2){a[0]=0;a[1]=ip3/100;a[2]=ip3/10%10;a[3]=ip3%10;delay(2000);w++;}
 if(w==3){a[0]=0;a[1]=ip4/100;a[2]=ip4/10%10;a[3]=ip4%10;delay(2000);w++;}}   
   }
  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          webPage +="<td colspan='2'><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td colspan='2'><center><big>Текущее время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);

          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204);
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
}      

void handleOk(){
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);
 
  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 
   
    ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D1 и перезагрузите ESP32</p><br>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
    }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
}   

10

Re: ESP32 ретро часы (разработка)

Доработка меню авторизации в сети, после ввода параметров сети выводится ip адрес

http://forum.rcl-radio.ru/uploads/images/2021/03/fb6b2d097aa7bbc6cb68f7cf550fe40d.png

http://forum.rcl-radio.ru/uploads/images/2021/03/681889e48d6dd4adf80bcddb0ccd04ad.png

http://forum.rcl-radio.ru/uploads/images/2021/03/9b76d1c5f041f6d8a87b59ee1c514a39.png



#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night;
  byte a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int w,ip1,ip2,ip3,ip4,utc;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[0]; an=0; segment();anod();break;
     case 1: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[1]; an=1; segment();anod();break;
     case 2: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[2]; an=2; segment();anod();break;
     case 3: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[3]; an=3; segment();anod();break;
     case 4: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[4]; an=4; segment();anod();break;
     case 5: segm=10;an=10;segment();anod();delayMicroseconds(1300);segm=a[5]; an=5; segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23 
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
   ip1 = WiFi.localIP()[0];
   ip2 = WiFi.localIP()[1];
   ip3 = WiFi.localIP()[2];
   ip4 = WiFi.localIP()[3];
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM /////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 30, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  delay(1000);
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*100+mm;
///////// ///////////////  
 if(mm==30&&ss<10){
  switch(ss){
    case 0: sum=0000;break;
    case 1: sum=1111;break;
    case 2: sum=2222;break;
    case 3: sum=3333;break;
    case 4: sum=4444;break;
    case 5: sum=5555;break;
    case 6: sum=6666;break;
    case 7: sum=7777;break;
    case 8: sum=8888;break;
    case 9: sum=9999;break;}}
  
  a[0]=sum/1000;
  a[1]=sum/100%10;
  a[2]=sum/10%10;
  a[3]=sum%10;
  a[4]=hh/10;
  a[5]=hh%10;
  
   }
  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='5'>";
          webPage +="<td colspan='2'><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td colspan='2'><center><big>Текущее время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204);
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   timerAlarmWrite(timer, 35, false);
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}      

void handleOk(){
  timerAlarmWrite(timer, 35, false);
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);

  
 
  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 

  
  const char *ast_ssid_ap = ssid_ap.c_str();
  const char *ast_pass_ap = pass_ap.c_str();

   
    /////////////////////////
    
    WiFi.begin(ast_ssid_ap, ast_pass_ap);
      // Wait for connection
    while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
 ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D1 и перезагрузите ESP8266</p><br>";
    str +="<big><b><center>";
    str += WiFi.localIP().toString();
    str +="</b><hr>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
  }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer); 
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
}   

11

Re: ESP32 ретро часы (разработка)

http://forum.rcl-radio.ru/uploads/images/2021/03/5b7a856d2f56ef9786d40658eb5c7e0a.gif

12

Re: ESP32 ретро часы (разработка)

Финальный скетч

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night;
  long a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int w,ip1,ip2,ip3,ip4,utc;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: an=10;anod();delayMicroseconds(2000);segm=a[0]; an=0; segment();anod();break;
     case 1: an=10;anod();delayMicroseconds(2000);segm=a[1]; an=1; segment();anod();break;
     case 2: an=10;anod();delayMicroseconds(2000);segm=a[2]; an=2; segment();anod();break;
     case 3: an=10;anod();delayMicroseconds(2000);segm=a[3]; an=3; segment();anod();break;
     case 4: an=10;anod();delayMicroseconds(2000);segm=a[4]; an=4; segment();anod();break;
     case 5: an=10;anod();delayMicroseconds(2000);segm=a[5]; an=5; segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23 
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
   ip1 = WiFi.localIP()[0];
   ip2 = WiFi.localIP()[1];
   ip3 = WiFi.localIP()[2];
   ip4 = WiFi.localIP()[3];
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM /////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  delay(1000);
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*10000+mm*100+ss;
///////// ///////////////  
 if(mm==30&&ss<10){
  switch(ss){
    case 0: sum=000000;break;
    case 1: sum=111111;break;
    case 2: sum=222222;break;
    case 3: sum=333333;break;
    case 4: sum=444444;break;
    case 5: sum=555555;break;
    case 6: sum=666666;break;
    case 7: sum=777777;break;
    case 8: sum=888888;break;
    case 9: sum=999999;break;}}
  
  a[0]=sum/100000;
  a[1]=sum/10000%10;
  a[2]=sum/1000%10;
  a[3]=sum/100%10;
  a[4]=sum/10%10;
  a[5]=sum%10;
  
   }
  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
          delay(300);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='5'>";
          webPage +="<td colspan='2'><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td colspan='2'><center><big>Текущее время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204);
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}      

void handleOk(){
  timerAlarmWrite(timer, 35, false);
  delay(300);
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);

  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 

  const char *ast_ssid_ap = ssid_ap.c_str();
  const char *ast_pass_ap = pass_ap.c_str();
    /////////////////////////
    WiFi.begin(ast_ssid_ap, ast_pass_ap);
      // Wait for connection
    while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
 ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D23 и перезагрузите ESP32</p><br>";
    str +="<big><b><center>";
    str += WiFi.localIP().toString();
    str +="</b><hr>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
  }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer); 
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
}   

Ток потребления
http://forum.rcl-radio.ru/uploads/images/2021/04/afe3024fa7ad3b8bb8af804a09de544d.png

http://forum.rcl-radio.ru/uploads/images/2021/04/bc91b0d4a512478e2aeec09a27145f0f.png

http://forum.rcl-radio.ru/uploads/images/2021/04/3c5555cd4f4c004686d0019bdcd8c221.png

13

Re: ESP32 ретро часы (разработка)

http://forum.rcl-radio.ru/uploads/images/2021/04/2003ad9bb9e909b253a2bd86ff1c8177.jpg

14

Re: ESP32 ретро часы (разработка)

15

Re: ESP32 ретро часы (разработка)

Доработка №1

Добавление в меню режима антиотравления катодов, перебор цифр 1-4 раза в час.

http://forum.rcl-radio.ru/uploads/images/2021/04/73cd62f39d0f82ee81e50703f9ee47aa.png

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night;
  long a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int utc,annti;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: an=10;anod();delayMicroseconds(2000);segm=a[0]; an=0; segment();anod();break;
     case 1: an=10;anod();delayMicroseconds(2000);segm=a[1]; an=1; segment();anod();break;
     case 2: an=10;anod();delayMicroseconds(2000);segm=a[2]; an=2; segment();anod();break;
     case 3: an=10;anod();delayMicroseconds(2000);segm=a[3]; an=3; segment();anod();break;
     case 4: an=10;anod();delayMicroseconds(2000);segm=a[4]; an=4; segment();anod();break;
     case 5: an=10;anod();delayMicroseconds(2000);segm=a[5]; an=5; segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23 
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  annti = EEPROM.read(205);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM /////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  delay(100);
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*10000+mm*100+ss;
///////// ///////////////
 switch(annti){
  case 1: if(mm==30&&ss<10){anti();}break;
  case 2: if((mm==15||mm==45)&&ss<10){anti();}break;
  case 3: if((mm==15||mm==30||mm==45)&&ss<10){anti();}break;
  case 4: if((mm==5||mm==20||mm==35||mm==50)&&ss<10){anti();}break;
  }  
  
  a[0]=sum/100000;
  a[1]=sum/10000%10;
  a[2]=sum/1000%10;
  a[3]=sum/100%10;
  a[4]=sum/10%10;
  a[5]=sum%10;
  
   }
  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
          delay(300);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='5'>";
          webPage +="<td colspan='2'><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td colspan='2'><center><big>Текущее время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204); 
          webPage += "<tr><td colspan='2'><input name='annti'  autocomplete='off' maxlength='3' size='1'> Антиотравление катодов индикаторов";
          webPage += "<br><small>Перебор всех цифр 1...4 раза в час, 5 - отключено. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(205);
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     if (server.argName(i) == "annti"){annti = server.arg(i).toInt();}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
    if(annti==NULL){}else{EEPROM.write(205,annti);}
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    annti = EEPROM.read(205);
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}      

void handleOk(){
  timerAlarmWrite(timer, 35, false);
  delay(300);
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);

  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 

  const char *ast_ssid_ap = ssid_ap.c_str();
  const char *ast_pass_ap = pass_ap.c_str();
    /////////////////////////
    WiFi.begin(ast_ssid_ap, ast_pass_ap);
      // Wait for connection
    while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
 ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D23 и перезагрузите ESP32</p><br>";
    str +="<big><b><center>";
    str += WiFi.localIP().toString();
    str +="</b><hr>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
  }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer); 
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
} 

void anti(){
    switch(ss){
    case 0: sum=000000;break;
    case 1: sum=111111;break;
    case 2: sum=222222;break;
    case 3: sum=333333;break;
    case 4: sum=444444;break;
    case 5: sum=555555;break;
    case 6: sum=666666;break;
    case 7: sum=777777;break;
    case 8: sum=888888;break;
    case 9: sum=999999;break;}
  }  

16

Re: ESP32 ретро часы (разработка)

Доработка №2

Вывод на индикаторы даты и месяца (в течении 4 секунд каждую минуту в 30 секунд), активация режима в меню.

http://forum.rcl-radio.ru/uploads/images/2021/04/fde85063cabc84a95775eaf086dc26ec.png

http://forum.rcl-radio.ru/uploads/images/2021/04/1822ca51938979a02fd684c95c3ff7ce.png

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int dd,mon,yer,ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night,gas,gas_d;
  long a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int utc,annti;
  String date_time,date;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: an=10;anod();delayMicroseconds(2000);segm=a[0]; an=0; segment();anod();break;
     case 1: an=10;anod();delayMicroseconds(2000);segm=a[1]; an=1; segment();anod();break;
     case 2: an=10;anod();delayMicroseconds(2000);segm=a[2]; an=2; segment();anod();break;
     case 3: an=10;anod();delayMicroseconds(2000);segm=a[3]; an=3; segment();anod();break;
     case 4: an=10;anod();delayMicroseconds(2000);segm=a[4]; an=4;if(gas==1){an=10;anod();} segment();anod();break;
     case 5: an=10;anod();delayMicroseconds(2000);segm=a[5]; an=5;if(gas==1){an=10;anod();} segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23 
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  annti = EEPROM.read(205);
  gas_d = EEPROM.read(206);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM /////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  delay(100);
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();

   date_time = timeClient.getFormattedDate();
   int index_date = date_time.indexOf("T");
   date = date_time.substring(0, index_date);
   char charBufVar[11];date.toCharArray(charBufVar, 11);
   dd = int(charBufVar[0]-'0')*10+int(charBufVar[1]-'0');
   mon = int(charBufVar[3]-'0')*10+int(charBufVar[4]-'0');
  // yer = int(charBufVar[8]-'0')*10+int(charBufVar[9]-'0');
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*10000+mm*100+ss;
 if(ss>=30&&ss<35&&gas_d==1){gas=1;sum = dd*10000+mon*100;}else{gas=0;}
///////// ///////////////
 switch(annti){
  case 1: if(mm==30&&ss<10){anti();}break;
  case 2: if((mm==15||mm==45)&&ss<10){anti();}break;
  case 3: if((mm==15||mm==30||mm==45)&&ss<10){anti();}break;
  case 4: if((mm==5||mm==20||mm==35||mm==50)&&ss<10){anti();}break;
  }  
  
  a[0]=sum/100000;
  a[1]=sum/10000%10;
  a[2]=sum/1000%10;
  a[3]=sum/100%10;
  a[4]=sum/10%10;
  a[5]=sum%10;
  
   }
  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
          delay(300);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='5'>";
          webPage +="<td colspan='2'><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td colspan='2'><center><big>Текущее время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204); 
          webPage += "<tr><td colspan='2'><input name='annti'  autocomplete='off' maxlength='3' size='1'> Антиотравление катодов индикаторов";
          webPage += "<br><small>Перебор всех цифр 1...4 раза в час, 5 - отключено. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(205);
          webPage += "<tr><td colspan='2'><input name='gas_d'  autocomplete='off' maxlength='3' size='1'> Индикация даты и месяца: 1 - вкл. | 2 - откл.";
          webPage += "<br><small>Показ даты и месяца каждую минуту в 30 секунд. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(206); 
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     if (server.argName(i) == "annti"){annti = server.arg(i).toInt();}
     if (server.argName(i) == "gas_d"){gas_d = server.arg(i).toInt();}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
    if(annti==NULL){}else{EEPROM.write(205,annti);}
    if(gas_d==NULL){}else{EEPROM.write(206,gas_d);}
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    annti = EEPROM.read(205);
    gas_d = EEPROM.read(206);
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}      

void handleOk(){
  timerAlarmWrite(timer, 35, false);
  delay(300);
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);

  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 

  const char *ast_ssid_ap = ssid_ap.c_str();
  const char *ast_pass_ap = pass_ap.c_str();
    /////////////////////////
    WiFi.begin(ast_ssid_ap, ast_pass_ap);
      // Wait for connection
    while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
 ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D23 и перезагрузите ESP32</p><br>";
    str +="<big><b><center>";
    str += WiFi.localIP().toString();
    str +="</b><hr>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
  }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer); 
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
} 

void anti(){
    switch(ss){
    case 0: sum=000000;break;
    case 1: sum=111111;break;
    case 2: sum=222222;break;
    case 3: sum=333333;break;
    case 4: sum=444444;break;
    case 5: sum=555555;break;
    case 6: sum=666666;break;
    case 7: sum=777777;break;
    case 8: sum=888888;break;
    case 9: sum=999999;break;}
  }  

17

Re: ESP32 ретро часы (разработка)

Доработка №2.1

Вывод на индикаторы даты, месяца и года(в течении 4 секунд каждую минуту в 30 секунд), активация режима в меню.

http://forum.rcl-radio.ru/uploads/images/2021/04/b1ca9e19faf15947c6921f87005fe876.png

http://forum.rcl-radio.ru/uploads/images/2021/04/57548f16d1fde7676f357f234635cdfa.png

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3600123);// 21600 - временной сдвиг в секундах от UTC 
  
  int dd,mon,yer,ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night,gas_d;
  long a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int utc,annti;
  String date_time,date;
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: an=10;anod();delayMicroseconds(2000);segm=a[0]; an=0; segment();anod();break;
     case 1: an=10;anod();delayMicroseconds(2000);segm=a[1]; an=1; segment();anod();break;
     case 2: an=10;anod();delayMicroseconds(2000);segm=a[2]; an=2; segment();anod();break;
     case 3: an=10;anod();delayMicroseconds(2000);segm=a[3]; an=3; segment();anod();break;
     case 4: an=10;anod();delayMicroseconds(2000);segm=a[4]; an=4; segment();anod();break;
     case 5: an=10;anod();delayMicroseconds(2000);segm=a[5]; an=5; segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); 
  pinMode(23,INPUT_PULLUP);// D23 
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  annti = EEPROM.read(205);
  gas_d = EEPROM.read(206);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM /////////////////////////  
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 1
  ledcAttachPin(15, 2);   // D15 / cannel 1
  ledcWrite(2, 255-brignes);  
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  delay(100);
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();

   date_time = timeClient.getFormattedDate();
   int index_date = date_time.indexOf("T");
   date = date_time.substring(0, index_date);
   char charBufVar[11];date.toCharArray(charBufVar, 11);
   dd = int(charBufVar[0]-'0')*10+int(charBufVar[1]-'0');
   mon = int(charBufVar[3]-'0')*10+int(charBufVar[4]-'0');
   yer = int(charBufVar[8]-'0')*10+int(charBufVar[9]-'0');
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*10000+mm*100+ss;
 if(ss>=30&&ss<35&&gas_d==1){sum = dd*10000+mon*100+yer;}
///////// ///////////////
 switch(annti){
  case 1: if(mm==30&&ss<10){anti();}break;
  case 2: if((mm==15||mm==45)&&ss<10){anti();}break;
  case 3: if((mm==15||mm==30||mm==45)&&ss<10){anti();}break;
  case 4: if((mm==5||mm==20||mm==35||mm==50)&&ss<10){anti();}break;
  }  
  
  a[0]=sum/100000;
  a[1]=sum/10000%10;
  a[2]=sum/1000%10;
  a[3]=sum/100%10;
  a[4]=sum/10%10;
  a[5]=sum%10;
  
   }
  
}// loop

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
          delay(300);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='5'>";
          webPage +="<td colspan='2'><h1><center>ESP32<br>Страница настройки Интернет часов</h1>";
          webPage +="<tr><td colspan='2'><center><big>Текущее время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204); 
          webPage += "<tr><td colspan='2'><input name='annti'  autocomplete='off' maxlength='3' size='1'> Антиотравление катодов индикаторов";
          webPage += "<br><small>Перебор всех цифр 1...4 раза в час, 5 - отключено. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(205);
          webPage += "<tr><td colspan='2'><input name='gas_d'  autocomplete='off' maxlength='3' size='1'> Индикация DD MM YY: 1 - вкл. | 2 - откл.";
          webPage += "<br><small>Дата, месяц и год показывается 1 раз в минуту (в 30 сек). Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(206); 
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     if (server.argName(i) == "annti"){annti = server.arg(i).toInt();}
     if (server.argName(i) == "gas_d"){gas_d = server.arg(i).toInt();}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
    if(annti==NULL){}else{EEPROM.write(205,annti);}
    if(gas_d==NULL){}else{EEPROM.write(206,gas_d);}
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    annti = EEPROM.read(205);
    gas_d = EEPROM.read(206);
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}      

void handleOk(){
  timerAlarmWrite(timer, 35, false);
  delay(300);
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);

  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 

  const char *ast_ssid_ap = ssid_ap.c_str();
  const char *ast_pass_ap = pass_ap.c_str();
    /////////////////////////
    WiFi.begin(ast_ssid_ap, ast_pass_ap);
      // Wait for connection
    while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
 ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D23 и перезагрузите ESP32</p><br>";
    str +="<big><b><center>";
    str += WiFi.localIP().toString();
    str +="</b><hr>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
  }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer); 
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
} 

void anti(){
    switch(ss){
    case 0: sum=000000;break;
    case 1: sum=111111;break;
    case 2: sum=222222;break;
    case 3: sum=333333;break;
    case 4: sum=444444;break;
    case 5: sum=555555;break;
    case 6: sum=666666;break;
    case 7: sum=777777;break;
    case 8: sum=888888;break;
    case 9: sum=999999;break;}
  }  

18

Re: ESP32 ретро часы (разработка)

Доработка №3.

Добавлено два будильника, будильник работает в нескольких режимах: по будням, по выходным, каждый день, выключено. Добавлена кнопка отключения сигнала будильника.

http://forum.rcl-radio.ru/uploads/images/2021/04/57eb9e23d66d7cd7969683870f96efde.png

http://forum.rcl-radio.ru/uploads/images/2021/04/c996c9228b567d848d5cf78b6c4c6fbf.gif

Схема архив - Данный контент доступен только зарегистрированным пользователям.

#define ID1 2
#define ID2 4
#define ID4 16
#define ID8 17

#define IN1 25
#define IN2 26
#define IN3 27
#define IN4 14
#define IN5 12
#define IN6 13

#include <WiFi.h>
#include <NTPClient.h>         // http://rcl-radio.ru/wp-content/uploads/2019/11/ntpclientmaster.zip
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <EEPROM.h>
#include "esp_system.h"

#ifndef APSSID
#define APSSID "ESPap"
#define APPSK  "12345678"
#endif

  const char *ssid = APSSID;
  const char *password = APPSK;
  WebServer server(80);
  WiFiUDP ntpUDP;
  /////////////////  https://www.ntppool.org/zone/@ - другие сервера  /////////////////////////////
  ///////////////// для России - ru.pool.ntp.org //////////////////////////////////////////////////
  NTPClient timeClient(ntpUDP, "pool.ntp.org", 21600,3601234);// 21600 - временной сдвиг в секундах от UTC 
  
  int dd,mon,yer,ss,mm,hh,i,an,segm,brignes,brignes_low, end_night,start_night,gas_d;
  long a[6];
  unsigned long times, sum, times1;
  byte len_ssid, len_pass;
  int utc,annti;
  String date_time,date;
  int alarm1,alarm2,al1_h,al1_m,al2_h,al2_m,bip1,bip2,out_alarm1,out_alarm2;
  char * d_n[7] = {"Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"};
  char * mon_n[13] = {"","Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "Октября", "Ноября", "Декабря"};
  hw_timer_t * timer = NULL;
  volatile SemaphoreHandle_t timerSemaphore;
  portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;


void IRAM_ATTR onTimer() {
      portENTER_CRITICAL_ISR(&timerMux);
  switch(i){
     case 0: an=10;anod();delayMicroseconds(2000);segm=a[0]; an=0; segment();anod();break;
     case 1: an=10;anod();delayMicroseconds(2000);segm=a[1]; an=1; segment();anod();break;
     case 2: an=10;anod();delayMicroseconds(2000);segm=a[2]; an=2; segment();anod();break;
     case 3: an=10;anod();delayMicroseconds(2000);segm=a[3]; an=3; segment();anod();break;
     case 4: an=10;anod();delayMicroseconds(2000);segm=a[4]; an=4; segment();anod();break;
     case 5: an=10;anod();delayMicroseconds(2000);segm=a[5]; an=5; segment();anod();break;
}
    i++;if(i>5){i=0;}
    portEXIT_CRITICAL_ISR(&timerMux);
    xSemaphoreGiveFromISR(timerSemaphore, NULL);
}



void setup(){ 
  timerSemaphore = xSemaphoreCreateBinary();
//////// GPIO ///////////////  
  pinMode(15,OUTPUT); // IRF840 PWM
  pinMode(23,INPUT_PULLUP);// AP/STA
  pinMode(22,OUTPUT);// ALARM PWM
  pinMode(33,INPUT_PULLUP);// ALARM OFF
  
  digitalWrite(15,HIGH);
  Serial.begin(9600);
//////// AP /////////////////
  if(digitalRead(23)==LOW){
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.on("/ok", handleOk);
  server.begin();
  Serial.println("HTTP server started");  
}
  else{
//////// STA ///////////////
  WiFi.mode( WIFI_STA);
  EEPROM.begin(512);
  len_ssid = EEPROM.read(96);
  len_pass = EEPROM.read(97);
  utc = EEPROM.read(201);
  brignes = EEPROM.read(200);
  brignes_low = EEPROM.read(202);
  start_night = EEPROM.read(203);
  end_night = EEPROM.read(204);
  annti = EEPROM.read(205);
  gas_d = EEPROM.read(206);
  alarm1 = EEPROM.read(210);
  al1_h = EEPROM.read(211);
  al1_m = EEPROM.read(212);
  alarm2 = EEPROM.read(220);
  al2_h = EEPROM.read(221);
  al2_m = EEPROM.read(222);
  if(brignes > 150){brignes=150;} 
  if(brignes_low > 150){brignes_low=150;} 
  if(len_pass > 64) len_pass = 0;
/////// READ EEPROM
  unsigned char* buf_ssid = new unsigned char[32];
  unsigned char* buf_pass = new unsigned char[64];
 for(byte i = 0; i < len_ssid; i++) buf_ssid[i] = char(EEPROM.read(i));
  buf_ssid[len_ssid] = '\x0';
  const char *ssid  = (const char*)buf_ssid;
 for(byte i = 0; i < len_pass; i++) buf_pass[i] = char(EEPROM.read(i + 32));
  const char *pass  = (const char*)buf_pass;
  buf_pass[len_pass] = '\x0';
  delay(2000);
  Serial.print("SSID: ");Serial.print(ssid);Serial.print("   ");Serial.print("Password: ");Serial.println(pass);
/////// connection       
  WiFi.begin(ssid, pass);
 while (WiFi.status() != WL_CONNECTED){delay(100);Serial.print (".");digitalWrite(15,HIGH);}
  Serial.println();Serial.print("Connected to ");Serial.println(ssid);Serial.print("IP address: ");Serial.println(WiFi.localIP());
  server.begin();
  server.on("/", web);
  server.on("/reset", web0);    
}
  
///////// PWM IRF840 //////////////////
  ledcSetup(2, 25000, 8); // 25000 kHz / 8 bit / cannel 2
  ledcAttachPin(15, 2);   // D15 / cannel 2
  ledcWrite(2, 255-brignes); 
///////// PWM ALARM ///////////////////
  ledcSetup(5, 2000, 8); 
  ledcAttachPin(22, 5); 
  ledcWrite(5, 0);
///////// TIMER 3 /////////////////////
  timer = timerBegin(3, 8000, true);
  timerAttachInterrupt(timer, &onTimer, false);
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer);    
///////////////////////////////////////  
  pinMode(IN1,OUTPUT);pinMode(IN2,OUTPUT);pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); pinMode(IN5,OUTPUT); 
  pinMode(IN6,OUTPUT); pinMode(ID1,OUTPUT); pinMode(ID2,OUTPUT); pinMode(ID4,OUTPUT); pinMode(ID8,OUTPUT); 
  timeClient.setTimeOffset(utc*1800);     
}


void loop(){
  if(bip1==0 && bip2==0){delay(100);}
  server.handleClient();
 if(digitalRead(23)==HIGH){
/////////////// times ////////////////////////////
  if(millis()-times>=1000){times=millis();
   while(!timeClient.update()){timeClient.forceUpdate();}
   hh = timeClient.getHours();
   mm = timeClient.getMinutes();
   ss = timeClient.getSeconds();

   date_time = timeClient.getFormattedDate();
   int index_date = date_time.indexOf("T");
   date = date_time.substring(0, index_date);
   char charBufVar[11];date.toCharArray(charBufVar, 11);
   dd = int(charBufVar[0]-'0')*10+int(charBufVar[1]-'0');
   mon = int(charBufVar[3]-'0')*10+int(charBufVar[4]-'0');
   yer = int(charBufVar[8]-'0')*10+int(charBufVar[9]-'0');
   Serial.print(hh/10);Serial.print(hh%10);Serial.print(":");Serial.print(mm/10);Serial.print(mm%10);Serial.print(":");Serial.print(ss/10);Serial.println(ss%10);
///// brightness  

   if(hh>=0&&hh<=end_night||hh>=start_night){ledcWrite(2, 255-brignes_low); }else {ledcWrite(2, 255-brignes);}
}
  sum = hh*10000+mm*100+ss;
 if(ss>=30&&ss<35&&gas_d==1){sum = dd*10000+mon*100+yer;}
///////// ///////////////
 switch(annti){
  case 1: if(mm==30&&ss<10){anti();}break;
  case 2: if((mm==15||mm==45)&&ss<10){anti();}break;
  case 3: if((mm==15||mm==30||mm==45)&&ss<10){anti();}break;
  case 4: if((mm==5||mm==20||mm==35||mm==50)&&ss<10){anti();}break;
  }  
  
  a[0]=sum/100000;
  a[1]=sum/10000%10;
  a[2]=sum/1000%10;
  a[3]=sum/100%10;
  a[4]=sum/10%10;
  a[5]=sum%10;


//////// ALARM //////////////////
 // 1 - каждый день, 2 - по будням, 3 - по выходным, 4 - откл.
 // 0 вс 6 сб
 if(out_alarm1==0 && alarm1==1 && hh*100+mm==al1_h*100+al1_m){bip1=1;}
 else if(out_alarm1==0 && alarm1==2 && (timeClient.getDay()>0 && timeClient.getDay()<6) && hh*100+mm==al1_h*100+al1_m){bip1=1;}
 else if(out_alarm1==0 && alarm1==3 && (timeClient.getDay()==0 || timeClient.getDay()==6) && hh*100+mm==al1_h*100+al1_m){bip1=1;}
 else{bip1=0;}

 if(out_alarm2==0 && alarm2==1 && hh*100+mm==al2_h*100+al2_m){bip2=1;}
 else if(out_alarm2==0 && alarm2==2 && (timeClient.getDay()>0 && timeClient.getDay()<6) && hh*100+mm==al2_h*100+al2_m){bip2=1;}
 else if(out_alarm2==0 && alarm2==3 && (timeClient.getDay()==0 || timeClient.getDay()==6) && hh*100+mm==al2_h*100+al2_m){bip2=1;}
 else{bip2=0;}

 if(digitalRead(33)==LOW){bip1=0;bip2=0;delay(200);out_alarm1=1;out_alarm2=1;}
 if(hh*100+mm!=al1_h*100+al1_m){out_alarm1=0;}
 if(hh*100+mm!=al2_h*100+al2_m){out_alarm2=0;}
 
 if(bip1==1 || bip2==1){alarm_bip_on();}
 if(bip1==0 && bip2==0){alarm_bip_off();}
 Serial.println(bip1);
   }
  
}// loop

void alarm_bip_on(){ledcWrite(5, 127);delay(200);ledcWrite(5, 0);delay(100);}
void alarm_bip_off(){ledcWrite(5, 0);}

void segment(){
  switch(segm){                                                                 
    case 0: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;     // DEC 0 = 0b0000
    case 1: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;    // DEC 1 = 0b0001
    case 2: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;    // DEC 2 = 0b0010
    case 3: digitalWrite(ID8,LOW);digitalWrite(ID4,LOW);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;   // DEC 3 = 0b0011
    case 4: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 4 = 0b0100
    case 5: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 5 = 0b0101
    case 6: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,LOW);break;   // DEC 6 = 0b0110
    case 7: digitalWrite(ID8,LOW);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break;  // DEC 7 = 0b0111
    case 8: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,LOW);break;    // DEC 8 = 0b1000
    case 9: digitalWrite(ID8,HIGH);digitalWrite(ID4,LOW);digitalWrite(ID2,LOW);digitalWrite(ID1,HIGH);break;   // DEC 9 = 0b1001
    case 10:digitalWrite(ID8,HIGH);digitalWrite(ID4,HIGH);digitalWrite(ID2,HIGH);digitalWrite(ID1,HIGH);break; // Пусто = 0b1111
    
  }}

  
void anod(){
  switch(an){                                                             
    case 0: digitalWrite(IN1,HIGH);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;    
    case 1: digitalWrite(IN1,LOW);digitalWrite(IN2,HIGH);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 2: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,HIGH);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
    case 3: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,HIGH);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;
    case 4: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,HIGH);digitalWrite(IN6,LOW);break;   
    case 5: digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,HIGH);break;
    case 10:digitalWrite(IN1,LOW);digitalWrite(IN2,LOW);digitalWrite(IN3,LOW);digitalWrite(IN4,LOW);digitalWrite(IN5,LOW);digitalWrite(IN6,LOW);break;   
  }}

void web(){ 
          timerAlarmWrite(timer, 35, false);
          delay(300);
   String webPage = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          webPage += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          webPage += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          webPage += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          webPage += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "#menu1 a:hover{color:#fff; background:#555;}";
          webPage += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          webPage += "</style></head>";
    /////////////   
          webPage += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='2'>";
          webPage +="<td colspan='2'><h3><center>ESP32<br>Страница настройки Интернет часов</h3>";
          webPage +="<tr><td colspan='2'><center>Время: ";         
          webPage += hh/10;webPage += hh%10; webPage +=":";webPage +=mm/10;
          webPage += mm%10; webPage +=":";webPage +=ss/10;webPage += ss%10;
          webPage += " | Дата: ";webPage += d_n[timeClient.getDay()];webPage += "  ";
          webPage += dd;webPage += " ";webPage += mon_n[mon];webPage += " ";webPage += " 20";webPage += yer;
          webPage += "</center>";
          webPage += "<form method='POST' action='reset' >";
          
          webPage += "<tr><td colspan='2'><b> Будильник №1 </b><input name='alarm1'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small> 1 - каждый день, 2 - по будням, 3 - по выходным, 4 - откл. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(210);
          webPage += "<br></small><input name='al1_h'  autocomplete='off' maxlength='3' size='1'> : ";
          webPage += "<input name='al1_m'  autocomplete='off' maxlength='3' size='1'> (HH:MM) ";
          webPage += "<small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(211)/10;webPage += EEPROM.read(211)%10;webPage += ":";
          EEPROM.begin(512);webPage += EEPROM.read(212)/10;webPage += EEPROM.read(212)%10;

          webPage += "<tr><td colspan='2'><b> Будильник №2 </b><input name='alarm2'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small> 1 - каждый день, 2 - по будням, 3 - по выходным, 4 - откл. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(220);
          webPage += "<br></small><input name='al2_h'  autocomplete='off' maxlength='3' size='1'> : ";
          webPage += "<input name='al2_m'  autocomplete='off' maxlength='3' size='1'> (HH:MM) ";
          webPage += "<small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(221)/10;webPage += EEPROM.read(221)%10;webPage += ":";
          EEPROM.begin(512);webPage += EEPROM.read(222)/10;webPage += EEPROM.read(222)%10;

          
          webPage += "<tr><td colspan='2'><input name='time_utc'  autocomplete='off' maxlength='3' size='1'> Временной сдвиг UTC (30 мин)";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(201);
          webPage += " (";webPage += utc*0.5;webPage += " ч.)";
          webPage += "<tr><td><input name='brignes'  autocomplete='off' maxlength='3' size='1'> Яркость день 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(200);
          webPage += "<td><input name='brignes_low'  autocomplete='off' maxlength='3' size='1'> Яркость ночь 0-150";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(202);
          webPage += "<tr><td colspan='2'><center> Время работы ночного режима подсветки <tr>";
          webPage += "<tr><td> Начало (18-23 ч) <input name='start_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(203);
          webPage += "<td> Конец: (1-12 ч) <input name='end_night'  autocomplete='off' maxlength='3' size='1'>";
          webPage += "<br><small>Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(204); 
          webPage += "<tr><td colspan='2'><input name='annti'  autocomplete='off' maxlength='3' size='1'> Антиотравление катодов индикаторов";
          webPage += "<br><small>Перебор всех цифр 1...4 раза в час, 5 - отключено. Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(205);
          webPage += "<tr><td colspan='2'><input name='gas_d'  autocomplete='off' maxlength='3' size='1'> Индикация DD MM YY: 1 - вкл. | 2 - откл.";
          webPage += "<br><small>Дата, месяц и год показывается 1 раз в минуту (в 30 сек). Установлено: ";EEPROM.begin(512);webPage += EEPROM.read(206); 
          

          webPage += "<tr><td colspan='2'><center><br><input type=SUBMIT value='Сохранить настройки'>";
          webPage += "</form>";
          webPage += "<center><br><small>Заполните все ячейки формы, незаполненная ячейка формы не изменит ранее установленный параметр";
         
          server.send(200, "text/html", webPage);
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
      
}

void sumbit(){ 
     if (server.args() > 0 ) {
   for ( uint8_t i = 0; i < server.args(); i++ ) {
     if (server.argName(i) == "brignes"){brignes = server.arg(i).toInt();}
     if (server.argName(i) == "time_utc"){utc = server.arg(i).toInt();}
     if (server.argName(i) == "brignes_low"){brignes_low = server.arg(i).toInt();}
     if (server.argName(i) == "start_night"){start_night = server.arg(i).toInt();}
     if (server.argName(i) == "end_night"){end_night = server.arg(i).toInt();}
     if (server.argName(i) == "annti"){annti = server.arg(i).toInt();}
     if (server.argName(i) == "gas_d"){gas_d = server.arg(i).toInt();}
     if (server.argName(i) == "alarm1"){alarm1 = server.arg(i).toInt();}
     if (server.argName(i) == "al1_h"){if(server.arg(i)==NULL){}else{al1_h = server.arg(i).toInt();EEPROM.write(211,al1_h);}}
     if (server.argName(i) == "al1_m"){if(server.arg(i)==NULL){}else{al1_m = server.arg(i).toInt();EEPROM.write(212,al1_m);}}
     if (server.argName(i) == "alarm2"){alarm2 = server.arg(i).toInt();}
     if (server.argName(i) == "al2_h"){if(server.arg(i)==NULL){}else{al2_h = server.arg(i).toInt();EEPROM.write(221,al2_h);}}
     if (server.argName(i) == "al2_m"){if(server.arg(i)==NULL){}else{al2_m = server.arg(i).toInt();EEPROM.write(222,al2_m);}}
     
  }
    Serial.println("Save");
    if(brignes > 150){brignes=150;} if(brignes < 0){brignes=0;}
    if(brignes_low > 150){brignes_low=150;} if(brignes_low < 0){brignes_low=0;}

    if(brignes==NULL){}else{EEPROM.write(200,brignes);}
    if(utc==NULL){}else{EEPROM.write(201,utc);}
    if(brignes_low==NULL){}else{EEPROM.write(202,brignes_low);}
    if(start_night==NULL){}else{EEPROM.write(203,start_night);}
    if(end_night==NULL){}else{EEPROM.write(204,end_night);}
    if(annti==NULL){}else{EEPROM.write(205,annti);}
    if(gas_d==NULL){}else{EEPROM.write(206,gas_d);}
    if(alarm1==NULL){}else{EEPROM.write(210,alarm1);}
    if(alarm2==NULL){}else{EEPROM.write(220,alarm2);}
 
        
    EEPROM.commit();
    EEPROM.end(); 
    EEPROM.begin(512);
    brignes = EEPROM.read(200); 
    utc = EEPROM.read(201);
    brignes_low = EEPROM.read(202);
    start_night = EEPROM.read(203);
    end_night = EEPROM.read(204); 
    annti = EEPROM.read(205);
    gas_d = EEPROM.read(206);
    alarm1 = EEPROM.read(210);
    al1_h = EEPROM.read(211);
    al1_m = EEPROM.read(212);
    alarm2 = EEPROM.read(220);
    al2_h = EEPROM.read(221);
    al2_m = EEPROM.read(222);
    
    timeClient.setTimeOffset(utc*1800);
    if(hh>=0&&hh<=6||hh>=23){ledcWrite(2, 255-brignes_low);}else {ledcWrite(2, 255-brignes);}
}}  

void handleRoot() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
   //style
          str += "<head><style>.tab1 {background-color:#F5F5F5;border-radius: 5px;margin: auto;}";
          str += "#menu1{list-style:none; width:100%; padding:0 0 0 0 ; margin: 0 0 0 0;background: #999;}";
          str += "#menu1 li{float:left; font:bold 14px Arial;text-shadow: 1px 1px 0px #000;}";
          str += "#menu1 a{color:#fff; display:block; height:36px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "#menu1 a:hover{color:#fff; background:#555;}";
          str += "#menu1 b{color:#fff; display:block; height:25px; line-height:36px; padding:10px 10px 10px 10px; background:#4682B4; text-decoration:none;}";
          str += "</style></head>";
   ////////////       
          str += "<TABLE class='tab1' align='center' width='470' BORDER='1' cellspacing='0' cellpadding='10'>";
          str +="<td><h1><center>ESP32<br>Авторизация</h1>";
          str += "<form method='POST' action='ok'>";
          str += "<tr><td><input name='ssid'  autocomplete='off'><big> Имя Wi-Fi сети";
          str += "<tr><td><input name='pswd'  autocomplete='off'><big> Пароль";
          str += "<tr><td><center><input type=SUBMIT value='Сохранить настройки'>";
          str += "</form>";
          server.send ( 200, "text/html", str );
          timerAlarmWrite(timer, 35, true);
          timerAlarmEnable(timer); 
}      

void handleOk(){
  timerAlarmWrite(timer, 35, false);
  delay(300);
  String ssid_ap;
  String pass_ap;
  unsigned char* buf = new unsigned char[64];
 
  String str = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";;
  str += "<body>";
 
  EEPROM.begin(512);
 
  ssid_ap = server.arg(0);
  pass_ap = server.arg(1);

  if(ssid_ap != ""){
    EEPROM.write(96,ssid_ap.length());
    EEPROM.write(97,pass_ap.length());
    ssid_ap.getBytes(buf, ssid_ap.length() + 1);
    for(byte i = 0; i < ssid_ap.length(); i++)
    EEPROM.write(i, buf[i]); 
    pass_ap.getBytes(buf, pass_ap.length() + 1);
    for(byte i = 0; i < pass_ap.length(); i++)
    EEPROM.write(i + 32, buf[i]);
    EEPROM.commit();
    EEPROM.end(); 

  const char *ast_ssid_ap = ssid_ap.c_str();
  const char *ast_pass_ap = pass_ap.c_str();
    /////////////////////////
    WiFi.begin(ast_ssid_ap, ast_pass_ap);
      // Wait for connection
    while (WiFi.status() != WL_CONNECTED){delay (10);Serial.print (".");}
 ///////////////////////////////////////////////////////////////////////////  
    str +="<big><center>Конфигурация сохранена в память<br>";
    str +="<big><center>Уберите перемычку с D23 и перезагрузите ESP32</p><br>";
    str +="<big><b><center>";
    str += WiFi.localIP().toString();
    str +="</b><hr>";
    str +="<a href=\"/\">Return</a> to settings page</br>";
  }
  else {
    str += "<big><center>No WIFI Net</br>\
   <a href=\"/\">Return</a> to settings page</br>";
  }
  str += "</body></html>";
  server.send ( 200, "text/html", str );
  timerAlarmWrite(timer, 35, true);
  timerAlarmEnable(timer); 
}


void web0() { 
   timerAlarmWrite(timer, 35, false);
   delay(300);
   String str0 = "<meta charset='utf-8'><meta name='viewport' content='width=480, user-scalable=no' />";
          str0 += "<center><b><big>Настройки сохранены.<br> Для возврата на предыдущую страницу перейдите по <a href='./'>ссылке</a>";
   server.send (200, "text/html", str0);
   sumbit();
   timerAlarmWrite(timer, 35, true);
   timerAlarmEnable(timer); 
} 

void anti(){
    switch(ss){
    case 0: sum=000000;break;
    case 1: sum=111111;break;
    case 2: sum=222222;break;
    case 3: sum=333333;break;
    case 4: sum=444444;break;
    case 5: sum=555555;break;
    case 6: sum=666666;break;
    case 7: sum=777777;break;
    case 8: sum=888888;break;
    case 9: sum=999999;break;}
  }  

19

Re: ESP32 ретро часы (разработка)

залил скетч прописал пароль и логин своего роутера и не могу зайти по выданному адресу 192.168.1.8 ни с ноутбука по вай фай ни с андроид телефона.. что посоветуете?

20

Re: ESP32 ретро часы (разработка)

прошивка которая с будильниками.

21

Re: ESP32 ретро часы (разработка)

Откройте монитор порта нажмите на кнопку reset (на плате ESP), посмотрите в мониторе порта IP и происходит ли подключение. Если подключение происходит, то Вы увидите отсчет часов.

22

Re: ESP32 ретро часы (разработка)

Отсчёт часов идёт, адрес показывает 192.168.1.8 , но время показывает неправильно , как же зайти в настройки мне, выставить будильники, время и прочее..

23

Re: ESP32 ретро часы (разработка)

http://192.168.1.8

24

Re: ESP32 ретро часы (разработка)

Сайт http://192.168.1.8/ недоступен.
ERR_ADDRESS_UNREACHABLE

25

Re: ESP32 ретро часы (разработка)

Перемычку с D23 убрали, перезагрузили esp