void btime()
{ 
 // bool lastate;
   current_time = hour1 * 60 + min1;
   Serial.println(current_time);
  //  state1 = main_log(BTimer1, state1);  //______________________Обработка каналов управления суточных таймеров реального времени (каналы 1 - 3)
  Serial.print("BTimer1 [0]:");
             Serial.println(BTimer1 [0]);
   Serial.print("BTimer2 [0]:");
             Serial.println(BTimer2 [0]);
     Serial.print("BTimer3 [0]:");
             Serial.println(BTimer3 [0]);
 //*******************************3************************************************************
  switch (BTimer3[0]) {
      case 0: 
     state3=0;
     if(gpioTimer3[0]==1)
     {digitalWrite(4, 0);
     gpio[0]=0;
     }
     if(gpioTimer3[1]==1)
     {digitalWrite(26, 0);
     gpio[1]=0;
     }
     if(gpioTimer3[2]==1)
     {digitalWrite(27, 0);
     gpio[2]=0;
     }
    break;
    case 1: 
    state3=1;
    if(gpioTimer3[0]==1)
     {digitalWrite(4, 1);
     gpio[0]=1;
     }
     if(gpioTimer3[1]==1)
     {digitalWrite(26, 1);
     gpio[1]=1;
     }
     if(gpioTimer3[2]==1)
     {digitalWrite(27, 1);
     gpio[2]=1;
     }
      break;
    case 2: 
    state3 = main_log(BTimer3, state3);
    if(gpioTimer3[0]==1)
     {digitalWrite(4, state3);
     gpio[0]=state3;
     }
     if(gpioTimer3[1]==1)
     {digitalWrite(26, state3);
     gpio[1]=state3;
     }
     if(gpioTimer3[2]==1)
     {digitalWrite(27, state3);
     gpio[2]=state3;
     }
      break;
      case 3:  
      break;
  }
  
 //****************************2***************************************************************  
 
   switch (BTimer2[0]) {
    case 0: 
     state2=0;
     if(gpioTimer2[0]==1)
     {digitalWrite(4, 0);
     gpio[0]=0;
     }
     if(gpioTimer2[1]==1)
     {digitalWrite(26, 0);
     gpio[1]=0;
     }
     if(gpioTimer2[2]==1)
     {digitalWrite(27, 0);
     gpio[2]=0;
     }
    break;
    case 1: 
    state2=1;
    if(gpioTimer2[0]==1)
     {digitalWrite(4, 1);
     gpio[0]=1;
     }
     if(gpioTimer2[1]==1)
     {digitalWrite(26, 1);
     gpio[1]=1;
     }
     if(gpioTimer2[2]==1)
     {digitalWrite(27, 1);
     gpio[2]=1;
     }
      break;
    case 2: 
    state2 = main_log(BTimer2, state2);
    if(gpioTimer2[0]==1)
     {digitalWrite(4, state2);
     gpio[0]=state2;
     }
     if(gpioTimer2[1]==1)
     {digitalWrite(26, state2);
     gpio[1]=state2;
     }
     if(gpioTimer2[2]==1)
     {digitalWrite(27, state2);
     gpio[2]=state2;
     }
      break;
      case 3:  
      break;
  }
  //******************************1-приоритет****************************************************************

   switch (BTimer1 [0]) {
    case 0: 
     state1=0;
     if(gpioTimer1 [0]==1)
     {digitalWrite(4, 0);
     gpio[0]=0;
     }
     if(gpioTimer1 [1]==1)
     {digitalWrite(26, 0);
     gpio[1]=0;
     }
     if(gpioTimer1 [2]==1)
     {digitalWrite(27, 0);
     gpio[2]=0;
     }
    break;
    case 1: 
    state1=1;
    if(gpioTimer1 [0]==1)
     {digitalWrite(4, 1);
     gpio[0]=1;
     }
     if(gpioTimer1 [1]==1)
     {digitalWrite(26, 1);
     gpio[1]=1;
     }
     if(gpioTimer1 [2]==1)
     {digitalWrite(27, 1);
     gpio[2]=1;
     }
      break;
    case 2: 
   // lastate=state1;
    state1 = main_log(BTimer1, state1);
    if(gpioTimer1[0]==1)
     {digitalWrite(4, state1);
     gpio[0]=state1;
     }
     if(gpioTimer1[1]==1)
     {digitalWrite(26, state1);
     gpio[1]=state1;
     }
     if(gpioTimer1[2]==1)
     {digitalWrite(27, state1);
     gpio[2]=state1;
     }
    
      break;
      case 3:  
      break;
  }

     Serial.print("Timer1:");
             Serial.println(state1);
   Serial.print("Timer2:");
             Serial.println(state2);
  Serial.print("Timer3:");
             Serial.println(state3);
               Serial.print("Gpio4:");
             Serial.println(digitalRead(4));
   Serial.print("Gpio26:");
             Serial.println(digitalRead(26));
  Serial.print("Gpio27:");
             Serial.println(digitalRead(27));
   writepin();
    JSstringOut();//преобразуем состояние выходов gpio[3] в JSON
    webSocket.textAll(jsonStringout);// выводим всем клиентам w/s
    
}

bool main_log (uint16_t* timeMassive, bool cur_state) {  // Основная фунция расчета состояния каналов суточных таймеров реального времени
  uint16_t j = 1440;
  uint8_t i = 0;
  uint8_t n = 0;
  for ( i = 1;  i < 11; i++) { //___________________________Ищем в массиве таймеров элемент соответсвующий текущему времени c значением не равным 1440 (означает неактивно, отображается "--:--")
    if ((timeMassive [i] == current_time) && (timeMassive [i] != 1440))  {
      j = timeMassive [i];
    }
  }
  if (j == 1440)return (cur_state); //_______________________Если не нашли оставляем состояние канала без изменений
  i = 0;
  for ( i = 1;  i < 11; i++) {
    if ((j == timeMassive [i]) && (timeMassive [i] != 1440))  {
      n = i;
    }
  }
  i = 0;
  if ((n % 2) == 0) { //____________________________________Четные таймеры выключают (LOW)
    return (LOW);
  }
  else return (HIGH); //____________________________________Нечетные таймеры включают (HIGH)
}
