Таймер 4 канала

sir_kimas
Offline
Зарегистрирован: 01.08.2016

Госпада помогите! Не могу реализовать, при бездействии переход на начальный экран и уменьшение подсветки на 50%

#define KEYBOARD A0
#define irrigator_relay 9                  
#define irrigator_relay2 10               
#define irrigator_relay3 11              
#define irrigator_relay4 12               
#include <EEPROM2.h>
//Создаем переменные для работы с термометром
byte TIn = 0;                            //переменная температуры воздуха
//Создаем переменные для работы с Гигрометром
int HumIn = 0;                           //переменная влажности воздуха

//Объявим переменную для хранения состояния реле

boolean relayStatusIrr1 = EEPROM_read_byte(53); //реле 
boolean relayStatusIrr2 = EEPROM_read_byte(54); //реле 
boolean relayStatusIrr3 = EEPROM_read_byte(55); //реле 
boolean relayStatusIrr4 = EEPROM_read_byte(56); //реле 

// подключение датчиков DHT11
#include <DHT.h>
#define DHTIN 8 //определяем пин
#define DHTTYPE DHT11     // DHT 11 

DHT dht(DHTIN, DHTTYPE);

//LCD 20x4 I2C
#include <LiquidCrystal_I2C.h>
// Глифы русских букв
byte yu[8] = {  //Ю
  B10010,
  B10101,
  B10101,
  B11101,
  B10101,
  B10101,
  B10010,
  B00000
};
byte ii[8] = {  //Ы
  B10001,
  B10001,
  B10001,
  B11101,
  B10101,
  B10101,
  B11101,
  B00000
};
byte che[8] = {  //Ч
  B10001,
  B10001,
  B10001,
  B01111,
  B00001,
  B00001,
  B00001,
  B00000
};
byte pe[8] = { //П
  0b11111,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b00000
};
byte ll[8] = { //Л
  0b00111,
  0b01001,
  0b01001,
  0b01001,
  0b01001,
  0b01001,
  0b10001,
  0b00000
};
byte u[8] = { //У
  B10001,
  B10001,
  B10001,
  B01010,
  B00100,
  B01000,
  B10000,
  B00000
};
byte i[8] = { //И
  B10001,
  B10011,
  B10101,
  B11001,
  B10001,
  B10001,
  B10001,
  B00000
};
byte be[8] = { //Б
  0b11111,
  0b10000,
  0b10000,
  0b11110,
  0b10001,
  0b10001,
  0b11110,
  0b00000
};

LiquidCrystal_I2C lcd(0x3F, 20, 4);
//клавиатуры - аналоговая
int button;
const int BUTTON_NONE   = 0;
const int BUTTON_RIGHT  = 5;
const int BUTTON_DOWN   = 4;
const int BUTTON_UP     = 3;
const int BUTTON_LEFT   = 2;
const int BUTTON_SELECT = 1;
byte flag = 0; //флаг былали нажата кнопка

//функция считывания клавиатуры 
byte getPressedButton()
{
  int buttonValue = analogRead(KEYBOARD);
  delay(100); //задержка для устранения дребезга
  if (buttonValue < 45) {
    return BUTTON_RIGHT;
  }
  else if (buttonValue < 200) {
    return BUTTON_DOWN;
  }
  else if (buttonValue < 380) {
    return BUTTON_UP;
  }
  else if (buttonValue < 550) {
    return BUTTON_LEFT;
  }
  else if (buttonValue < 760) {
    return BUTTON_SELECT;
  }
  return BUTTON_NONE;
}

byte Tday = 0; //день недели
byte regim = 0; //для меню
byte posic = 0;
byte flagIrrManual = 0; //флаг зона 1
byte flagIrrManual2 = 0; //флаг зона 2
byte flagIrrManual3 = 0; //флаг зона 3
byte flagIrrManual4 = 0; //флаг зона 4
byte Timer = 0; //таймера 1
byte Timer2 = 0; //таймера 2
byte Timer3 = 0; //таймера 3
byte Timer4 = 0; //таймера 4

byte TstartHour = 0; //часы таймера
byte TstartMinute = 0; //минуты таймера
byte TstopHour = 0; //часы интервала таймера
byte TstopMinute = 0; //минуты интервала таймера

byte TstartHour2, TstartMinute2, TstopHour2, TstopMinute2;
byte TstartHour3, TstartMinute3, TstopHour3, TstopMinute3;
byte TstartHour4, TstartMinute4, TstopHour4, TstopMinute4;

//ds3231 модуль часов реального времени
#include <Wire.h>
#include "DS3231.h" 
Time  t;

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.createChar(1, yu);
  lcd.createChar(2, ii);
  lcd.createChar(3, che);
  lcd.createChar(4, pe);
  lcd.createChar(5, ll);
  lcd.createChar(6, u);
  lcd.createChar(7, i);
  lcd.createChar(0, be);
  lcd.clear();
  lcd.print("   ");
  Wire.begin();
  rtc.begin();
  delay(5000);
  lcd.clear();

  dht.begin();

  //Настроим пин для управления реле
  pinMode(irrigator_relay, OUTPUT);
  digitalWrite(irrigator_relay, HIGH);
  pinMode(irrigator_relay2, OUTPUT);
  digitalWrite(irrigator_relay2, HIGH);
  pinMode(irrigator_relay3, OUTPUT);
  digitalWrite(irrigator_relay3, HIGH);
  pinMode(irrigator_relay4, OUTPUT);
  digitalWrite(irrigator_relay4, HIGH);

  pinMode (A0, INPUT_PULLUP);// подтягиваем питание на вход

}
void timeDS3231() //Обработка часов
{
  t = rtc.getTime();
}
//Обработка нажатия кнопки аналоговой
void Button_read()
{
  button = getPressedButton();
  if (button > 0) flag = 1;
}
//счит темп воздуха в теплице
void TInGet()
{
  TIn = int(dht.readTemperature());
}
//счит Влажн воздуха в теплице
void HumInGet()
{
  HumIn = int (dht.readHumidity());
}

//=========== Отработка канала
void  Irrigation()
{

  //1-й кнал
  Timer = EEPROM_read_byte(4); //включен или нет
  TstartHour = EEPROM_read_byte(5);
  TstartMinute = EEPROM_read_byte(6);
  TstopHour = EEPROM_read_byte(7);
  TstopMinute = EEPROM_read_byte(8);

  if (Timer == 0 && relayStatusIrr1 == HIGH) {
    lcd.setCursor(5, 3);
    lcd.print("x");
  }
  if (relayStatusIrr1 == LOW) {
    lcd.setCursor(5, 3);
    lcd.print("P");
  }
  if (Timer == 1 && relayStatusIrr1 == HIGH) {
    lcd.setCursor(5, 3);
    lcd.print("T");
  }
  if  (EEPROM_read_byte(53) == 1) {
    digitalWrite(irrigator_relay, LOW);
    relayStatusIrr1 = LOW;
    flagIrrManual = 0;
  }
  if  (EEPROM_read_byte(53) == 0) {
    digitalWrite(irrigator_relay, HIGH);
    relayStatusIrr1 = HIGH;
    flagIrrManual = 1;
  }

  if (Timer == 1)
  {
    byte i;
    for (i = 0; i < 7; i++)
    {
      if ((t.dow == i + 1) && EEPROM_read_byte(24 + i) == 1)
      {
        if (t.hour == TstartHour && t.min == TstartMinute) {
          digitalWrite(irrigator_relay, LOW);
          EEPROM_write_byte(53, 1);
        }
        else if (t.hour == TstopHour && t.min == TstopMinute) {
          digitalWrite(irrigator_relay, HIGH);
          EEPROM_write_byte(53, 0);
        }
      }
    }
  }
  if (Timer == 0)
  {
    digitalWrite(irrigator_relay, HIGH);
    EEPROM_write_byte(53, 0);
  }

  //2-й канал
  Timer2 = EEPROM_read_byte(9); //включен или нет
  TstartHour2 = EEPROM_read_byte(10);
  TstartMinute2 = EEPROM_read_byte(11);
  TstopHour2 = EEPROM_read_byte(12);
  TstopMinute2 = EEPROM_read_byte(13);

  if (Timer2 == 0 && relayStatusIrr2 == HIGH) {
    lcd.setCursor(9, 3);
    lcd.print("x");
  }
  if (relayStatusIrr2 == LOW) {
    lcd.setCursor(9, 3);
    lcd.print("P");
  }
  if (Timer2 == 1 && relayStatusIrr2 == HIGH) {
    lcd.setCursor(9, 3);
    lcd.print("T");
  }
  if  (EEPROM_read_byte(54) == 1) {
    digitalWrite(irrigator_relay2, LOW);
    relayStatusIrr2 = LOW;
    flagIrrManual2 = 0;
  }
  if  (EEPROM_read_byte(54) == 0) {
    digitalWrite(irrigator_relay2, HIGH);
    relayStatusIrr2 = HIGH;
    flagIrrManual2 = 1;
  }
  if (Timer2 == 1)
  {
    byte i;
    for (i = 0; i < 7; i++)
    {
      if ((t.dow == i + 1) && EEPROM_read_byte(31 + i) == 1)
      {
        if (t.hour == TstartHour2 && t.min == TstartMinute2) {
          digitalWrite(irrigator_relay2, LOW);
          EEPROM_write_byte(54, 1);
        }
        else if (t.hour == TstopHour2 && t.min == TstopMinute2) {
          digitalWrite(irrigator_relay2, HIGH);
          EEPROM_write_byte(54, 0);
        }
      }
    }
  }
  if (Timer2 == 0)
  {
    digitalWrite(irrigator_relay2, HIGH);
    EEPROM_write_byte(54, 0);
  }
  //3-й канал
  Timer3 = EEPROM_read_byte(14); //включен или нет
  TstartHour3 = EEPROM_read_byte(15);
  TstartMinute3 = EEPROM_read_byte(16);
  TstopHour3 = EEPROM_read_byte(17);
  TstopMinute3 = EEPROM_read_byte(18);

  if (Timer3 == 0 && relayStatusIrr3 == HIGH) {
    lcd.setCursor(13, 3);
    lcd.print("x");
  }
  if (relayStatusIrr3 == LOW) {
    lcd.setCursor(13, 3);
    lcd.print("P");
  }
  if (Timer3 == 1 && relayStatusIrr3 == HIGH) {
    lcd.setCursor(13, 3);
    lcd.print("T");
  }
  if  (EEPROM_read_byte(55) == 1) {
    digitalWrite(irrigator_relay3, LOW);
    relayStatusIrr3 = LOW;
    flagIrrManual3 = 0;
  }
  if  (EEPROM_read_byte(55) == 0) {
    digitalWrite(irrigator_relay3, HIGH);
    relayStatusIrr3 = HIGH;
    flagIrrManual3 = 1;
  }
  if (Timer3 == 1)
  {
    byte i;
    for (i = 0; i < 7; i++)
    {
      if ((t.dow == i + 1) && EEPROM_read_byte(38 + i) == 1)
      {
        if (t.hour == TstartHour3 && t.min == TstartMinute3) {
          digitalWrite(irrigator_relay3, LOW);
          EEPROM_write_byte(55, 1);
        }
        else if (t.hour == TstopHour3 && t.min == TstopMinute3) {
          digitalWrite(irrigator_relay3, HIGH);
          EEPROM_write_byte(55, 0);
        }
      }
    }
  }
  if (Timer3 == 0)
  {
    digitalWrite(irrigator_relay3, HIGH);
    EEPROM_write_byte(55, 0);
  }

  //4-й канал
  Timer4 = EEPROM_read_byte(19); //включен или нет
  TstartHour4 = EEPROM_read_byte(20);
  TstartMinute4 = EEPROM_read_byte(21);
  TstopHour4 = EEPROM_read_byte(22);
  TstopMinute4 = EEPROM_read_byte(23);

  if (Timer4 == 0 && relayStatusIrr4 == HIGH) {
    lcd.setCursor(17, 3);
    lcd.print("x");
  }
  if (relayStatusIrr4 == LOW) {
    lcd.setCursor(17, 3);
    lcd.print("P");
  }
  if (Timer4 == 1 && relayStatusIrr4 == HIGH) {
    lcd.setCursor(17, 3);
    lcd.print("T");
  }
  if  (EEPROM_read_byte(56) == 1) {
    digitalWrite(irrigator_relay4, LOW);
    relayStatusIrr4 = LOW;
    flagIrrManual4 = 0;
  }
  if  (EEPROM_read_byte(56) == 0) {
    digitalWrite(irrigator_relay4, HIGH);
    relayStatusIrr4 = HIGH;
    flagIrrManual4 = 1;
  }
  if (Timer4 == 1)
  {
    byte i;
    for (i = 0; i < 7; i++)
    {
      if ((t.dow == i + 1) && EEPROM_read_byte(45 + i) == 1)
      {
        if (t.hour == TstartHour4 && t.min == TstartMinute4) {
          digitalWrite(irrigator_relay4, LOW);
          EEPROM_write_byte(56, 1);
        }
        else if (t.hour == TstopHour4 && t.min == TstopMinute4) {
          digitalWrite(irrigator_relay4, HIGH);
          EEPROM_write_byte(56, 0);
        }
      }
    }

  }
  if (Timer4 == 0)
  {
    digitalWrite(irrigator_relay4, HIGH);
    EEPROM_write_byte(56, 0);
  }
}

void StaticButton()
{
  Button_read();
  if (button == 1 && flag == 1) {
    MenuSET();
  }
  if (button == 5 && flag == 1) {
    TimerViewer();
  }
}

//=========Вывод состояние таймеров (информативное окно)
void TimerViewer ()
{
  lcd.setCursor(0, 3); //чистим нижнюю строчку экрана, от левой инфы
  lcd.print("                    ");
  byte myArray[7] = {1, 4, 7, 10, 13, 16, 19}; // для выделения дней в которых уст. таймер
  byte i;
  do
  {
    Button_read();
    delay(100);
    if (button == 5 && flag == 1) {
      regim++;
      flag = 0;
    }
    if (regim == 1) //
    {
      lcd.setCursor(0, 0);
      lcd.print("[TA\7MEP 1] - ");
      if (Timer == 0) lcd.print("B\2K\5   ");
      if (Timer == 1) lcd.print("BK\5     ");
      TstartHour = EEPROM_read_byte(5);
      TstartMinute = EEPROM_read_byte(6);
      TstopHour = EEPROM_read_byte(7);
      TstopMinute = EEPROM_read_byte(8);
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour);
      lcd.print(":");
      if (TstartMinute < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour);
      lcd.print(":");
      if (TstopMinute < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute);
      lcd.setCursor(0, 2);
      lcd.print("\4H BT CP \3T \4T C");
      lcd.write(0);
      lcd.print(" BC");
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(24 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(24 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }
    }
    if (regim == 2) //
    {
      lcd.setCursor(0, 0);
      lcd.print("[TA\7MEP 2] - ");
      if (Timer2 == 0) lcd.print("B\2K\5   ");
      if (Timer2 == 1) lcd.print("BK\5     ");
      TstartHour2 = EEPROM_read_byte(10);
      TstartMinute2 = EEPROM_read_byte(11);
      TstopHour2 = EEPROM_read_byte(12);
      TstopMinute2 = EEPROM_read_byte(13);
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour2);
      lcd.print(":");
      if (TstartMinute2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute2);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour2);
      lcd.print(":");
      if (TstopMinute2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute2);
      lcd.setCursor(0, 2);
      lcd.print("\4H BT CP \3T \4T C");
      lcd.write(0);
      lcd.print(" BC");
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(31 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(31 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }
    }
    if (regim == 3) //
    {
      lcd.setCursor(0, 0);
      lcd.print("[TA\7MEP 3] - ");
      if (Timer3 == 0) lcd.print("B\2K\5   ");
      if (Timer3 == 1) lcd.print("BK\5     ");
      TstartHour3 = EEPROM_read_byte(15);
      TstartMinute3 = EEPROM_read_byte(16);
      TstopHour3 = EEPROM_read_byte(17);
      TstopMinute3 = EEPROM_read_byte(18);
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour3);
      lcd.print(":");
      if (TstartMinute3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute3);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour3);
      lcd.print(":");
      if (TstopMinute3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute3);
      lcd.setCursor(0, 2);
      lcd.print("\4H BT CP \3T \4T C");
      lcd.write(0);
      lcd.print(" BC");
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(38 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(38 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }
    }
    if (regim == 4)
    {
      lcd.setCursor(0, 0);
      lcd.print("[TA\7MEP 4] - ");
      if (Timer4 == 0) {
        lcd.print("B\2K\5   ");
      }
      if (Timer4 == 1) {
        lcd.print("BK\5     ");
      }
      TstartHour4 = EEPROM_read_byte(20);
      TstartMinute4 = EEPROM_read_byte(21);
      TstopHour4 = EEPROM_read_byte(22);
      TstopMinute4 = EEPROM_read_byte(23);
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour4);
      lcd.print(":");
      if (TstartMinute4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute4);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour4);
      lcd.print(":");
      if (TstopMinute4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute4);
      lcd.setCursor(0, 2);
      lcd.print("\4H BT CP \3T \4T C");
      lcd.write(0);
      lcd.print(" BC");
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(45 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(45 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }
    }
  }
  while (regim < 5);
  regim = 0;
}

//============Вход в Меню настроек и установок
void MenuSET()
{

  lcd.setCursor(0, 3); //чистим нижнюю строчку экрана, от левой инфы
  lcd.print("                    ");

  do
  {
    Button_read();
    delay(100);
    if (button == 1 && flag == 1) {
      regim++;
      flag = 0;
    }
    if (regim == 1) // режим Установка Времени Таймера 1 
    {
      Timer = EEPROM_read_byte(4);
      lcd.setCursor(0, 0);
      lcd.print("[1]\6CT TA\7MEP 1- ");
      if (Timer == 0) lcd.print("B\2K");
      if (Timer == 1) lcd.print("BK ");
      TstartHour = EEPROM_read_byte(5);
      TstartMinute = EEPROM_read_byte(6);
      TstopHour = EEPROM_read_byte(7);
      TstopMinute = EEPROM_read_byte(8);
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour);
      lcd.print(":");
      if (TstartMinute < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour);
      lcd.print(":");
      if (TstopMinute < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute);
      lcd.setCursor(0, 2);
      lcd.print("\4 B C \3 \4 C B Bce +");
      byte myArray[7] = {0, 2, 4, 6, 8, 10, 12};
      byte i;
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(24 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(24 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }
      {
        lcd.setCursor(1, 3);
        lcd.print(" ");
      }
      {
        lcd.setCursor(3, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(24) == 0 or EEPROM_read_byte(25) == 0 or EEPROM_read_byte(26) == 0 or EEPROM_read_byte(27) == 0 or EEPROM_read_byte(28) == 0 or EEPROM_read_byte(29) == 0 or EEPROM_read_byte(30) == 0) {
        lcd.setCursor(15, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(24) == 1 && EEPROM_read_byte(25) == 1 && EEPROM_read_byte(26) == 1 && EEPROM_read_byte(27) == 1 && EEPROM_read_byte(28) == 1 && EEPROM_read_byte(29) == 1 && EEPROM_read_byte(30) == 1) {
        lcd.setCursor(15, 3);
        lcd.print(char(94));
      }
      lcd.setCursor(17, 3);
      lcd.print("<->");

      lcd.blink();
      if (button == 5 && flag == 1) posic++;
      if (button == 2 && flag == 1) posic--;
      if (posic == 0)
      {
        lcd.setCursor(19, 0);
        if (button == 3 && flag == 1)
        { if (Timer < 1)  Timer++;
          else
            Timer = 0;
          EEPROM_write_byte(4, Timer);
        }
        if (button == 4 && flag == 1)
        { if (Timer > 0)  Timer--;
          else
            Timer = 1;
          EEPROM_write_byte(4, Timer);
        }
      }
      if (posic == 1)
      {
        lcd.setCursor(5, 1);
        if (button == 3 && flag == 1)
        { if (TstartHour < 23)  TstartHour++;
          else
            TstartHour = 0;
          EEPROM_write_byte(5, TstartHour);
        }
        if (button == 4 && flag == 1)
        { if (TstartHour > 0)  TstartHour--;
          else
            TstartHour = 23;
          EEPROM_write_byte(5, TstartHour);
        }
      }
      if (posic == 2)
      {
        lcd.setCursor(8, 1);
        if (button == 3 && flag == 1)
        { if (TstartMinute < 59)  TstartMinute++;
          else
            TstartMinute = 0;
          EEPROM_write_byte(6, TstartMinute);
        }
        if (button == 4 && flag == 1)
        { if (TstartMinute > 0)  TstartMinute--;
          else
            TstartMinute = 59;
          EEPROM_write_byte(6, TstartMinute);
        }
      }
      if (posic == 3)
      {
        lcd.setCursor(16, 1);
        if (button == 3 && flag == 1)
        { if (TstopHour < 23)  TstopHour++;
          else
            TstopHour = 0;
          EEPROM_write_byte(7, TstopHour);
        }
        if (button == 4 && flag == 1)
        { if (TstopHour > 0)  TstopHour--;
          else
            TstopHour = 23;
          EEPROM_write_byte(7, TstopHour);
        }
      }
      if (posic == 4)
      {
        lcd.setCursor(19, 1);
        if (button == 3 && flag == 1)
        { if (TstopMinute < 59)  TstopMinute++;
          else
            TstopMinute = 0;
          EEPROM_write_byte(8, TstopMinute);
        }
        if (button == 4 && flag == 1)
        { if (TstopMinute > 0)  TstopMinute--;
          else
            TstopMinute = 59;
          EEPROM_write_byte(8, TstopMinute);
        }
      }
      if (posic == 5) //устанавливаем дни недели для будильника "Все сразу"
      {
        lcd.setCursor(15, 2);
        if (button == 3 && flag == 1)
        {
          if (Tday < 1)  Tday++;
          else
            Tday = 0;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(24 + i, Tday);

        }
        if (button == 4 && flag == 1)
        {
          if (Tday > 0)  Tday--;
          else
            Tday = 1;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(24 + i, Tday);

        }
      }
      if (posic == 6) //устанавливаем будильника ПH
      {
        lcd.setCursor(0, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(24) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(24, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(24) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(24, Tday);
        }
      }
      if (posic == 7) //устанавливаем для будильника BT
      {
        lcd.setCursor(2, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(25) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(25, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(25) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(25, Tday);
        }
      }
      if (posic == 8) //устанавливаем для будильника СР
      {
        lcd.setCursor(4, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(26) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(26, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(26) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(26, Tday);
        }
      }
      if (posic == 9) //устанавливаем для будильника ЧТ
      {
        lcd.setCursor(6, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(27) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(27, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(27) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(27, Tday);
        }
      }
      if (posic == 10) //устанавливаем для будильника ПТ
      {
        lcd.setCursor(8, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(28) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(28, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(28) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(28, Tday);
        }
      }
      if (posic == 11) //устанавливаем для будильника СБ
      {
        lcd.setCursor(10, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(29) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(29, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(29) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(29, Tday);
        }
      }
      if (posic == 12) //устанавливаем для будильника ВС
      {
        lcd.setCursor(12, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(30) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(30, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(30) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(30, Tday);
        }
      }
      if (posic == 13) posic = 0; //возврат в начало
    }
    if (regim == 2) // режим Установка Времени Таймера 2 
    {
      Timer2 = EEPROM_read_byte(9);
      lcd.setCursor(0, 0);
      lcd.print("[2]\6CT TA\7MEP 2- ");
      if (Timer2 == 0) lcd.print("B\2K");
      if (Timer2 == 1) lcd.print("BK ");
      TstartHour2 = EEPROM_read_byte(10);
      TstartMinute2 = EEPROM_read_byte(11);
      TstopHour2 = EEPROM_read_byte(12);
      TstopMinute2 = EEPROM_read_byte(13);
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour2);
      lcd.print(":");
      if (TstartMinute2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute2);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour2);
      lcd.print(":");
      if (TstopMinute2 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute2);
      lcd.setCursor(0, 2);
      lcd.print("\4 B C \3 \4 C B Bce +");

      byte myArray[7] = {0, 2, 4, 6, 8, 10, 12};
      byte i;
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(31 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(31 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }

      {
        lcd.setCursor(1, 3);
        lcd.print(" ");
      }
      {
        lcd.setCursor(3, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(31) == 0 or EEPROM_read_byte(32) == 0 or EEPROM_read_byte(33) == 0 or EEPROM_read_byte(34) == 0 or EEPROM_read_byte(35) == 0 or EEPROM_read_byte(36) == 0 or EEPROM_read_byte(37) == 0) {
        lcd.setCursor(15, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(31) == 1 && EEPROM_read_byte(32) == 1 && EEPROM_read_byte(33) == 1 && EEPROM_read_byte(34) == 1 && EEPROM_read_byte(35) == 1 && EEPROM_read_byte(36) == 1 && EEPROM_read_byte(37) == 1) {
        lcd.setCursor(15, 3);
        lcd.print(char(94));
      }
      lcd.setCursor(17, 3);
      lcd.print("<->");

      lcd.blink();
      if (button == 5 && flag == 1) posic++;
      if (button == 2 && flag == 1) posic--;
      if (posic == 0)
      {
        lcd.setCursor(19, 0);
        if (button == 3 && flag == 1)
        { if (Timer2 < 1)  Timer2++;
          else
            Timer2 = 0;
          EEPROM_write_byte(9, Timer2);
        }
        if (button == 4 && flag == 1)
        { if (Timer2 > 0)  Timer2--;
          else
            Timer2 = 1;
          EEPROM_write_byte(9, Timer2);
        }
      }
      if (posic == 1)
      {
        lcd.setCursor(5, 1);
        if (button == 3 && flag == 1)
        { if (TstartHour2 < 23)  TstartHour2++;
          else
            TstartHour2 = 0;
          EEPROM_write_byte(10, TstartHour2);
        }
        if (button == 4 && flag == 1)
        { if (TstartHour2 > 0)  TstartHour2--;
          else
            TstartHour2 = 23;
          EEPROM_write_byte(10, TstartHour2);
        }
      }
      if (posic == 2)
      {
        lcd.setCursor(8, 1);
        if (button == 3 && flag == 1)
        { if (TstartMinute2 < 59)  TstartMinute2++;
          else
            TstartMinute2 = 0;
          EEPROM_write_byte(11, TstartMinute2);
        }
        if (button == 4 && flag == 1)
        { if (TstartMinute2 > 0)  TstartMinute2--;
          else
            TstartMinute2 = 59;
          EEPROM_write_byte(11, TstartMinute2);
        }
      }
      if (posic == 3)
      {
        lcd.setCursor(16, 1);
        if (button == 3 && flag == 1)
        { if (TstopHour2 < 23)  TstopHour2++;
          else
            TstopHour2 = 0;
          EEPROM_write_byte(12, TstopHour2);
        }
        if (button == 4 && flag == 1)
        { if (TstopHour2 > 0)  TstopHour2--;
          else
            TstopHour2 = 23;
          EEPROM_write_byte(12, TstopHour2);
        }
      }
      if (posic == 4)
      {
        lcd.setCursor(19, 1);
        if (button == 3 && flag == 1)
        { if (TstopMinute2 < 59)  TstopMinute2++;
          else
            TstopMinute2 = 0;
          EEPROM_write_byte(13, TstopMinute2);
        }
        if (button == 4 && flag == 1)
        { if (TstopMinute2 > 0)  TstopMinute2--;
          else
            TstopMinute2 = 59;
          EEPROM_write_byte(13, TstopMinute2);
        }
      }
      if (posic == 5) //устанавливаем дни недели для будильника "Все сразу"
      {
        lcd.setCursor(15, 2);
        if (button == 3 && flag == 1)
        {
          if (Tday < 1)  Tday++;
          else
            Tday = 0;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(31 + i, Tday);

        }
        if (button == 4 && flag == 1)
        {
          if (Tday > 0)  Tday--;
          else
            Tday = 1;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(31 + i, Tday);
        }
      }
      if (posic == 6) //устанавливаем будильника ПH
      {
        lcd.setCursor(0, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(31) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(31, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(31) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(31, Tday);
        }
      }
      if (posic == 7) //устанавливаем для будильника BT
      {
        lcd.setCursor(2, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(32) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(32, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(32) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(32, Tday);
        }
      }
      if (posic == 8) //устанавливаем для будильника СР
      {
        lcd.setCursor(4, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(33) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(33, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(33) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(33, Tday);
        }
      }
      if (posic == 9) //устанавливаем для будильника ЧТ
      {
        lcd.setCursor(6, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(34) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(34, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(34) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(34, Tday);
        }
      }
      if (posic == 10) //устанавливаем для будильника ПТ
      {
        lcd.setCursor(8, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(35) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(35, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(35) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(35, Tday);
        }
      }
      if (posic == 11) //устанавливаем для будильника СБ
      {
        lcd.setCursor(10, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(36) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(36, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(36) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(36, Tday);
        }
      }
      if (posic == 12) //устанавливаем для будильника ВС
      {
        lcd.setCursor(12, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(37) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(37, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(37) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(37, Tday);
        }
      }
      if (posic == 13) posic = 0; //возврат в начало
    }

    if (regim == 3) // режим Установка Времени Таймера 3 
    {
      Timer3 = EEPROM_read_byte(14);
      lcd.setCursor(0, 0);
      lcd.print("[3]\6CT TA\7MEP 3- ");
      if (Timer3 == 0) lcd.print("B\2K");
      if (Timer3 == 1) lcd.print("BK ");
      TstartHour3 = EEPROM_read_byte(15);
      TstartMinute3 = EEPROM_read_byte(16);
      TstopHour3 = EEPROM_read_byte(17);
      TstopMinute3 = EEPROM_read_byte(18);

      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      if (TstartHour3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour3);
      lcd.print(":");
      if (TstartMinute3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute3);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour3);
      lcd.print(":");
      if (TstopMinute3 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute3);
      lcd.setCursor(0, 2);
      lcd.print("\4 B C \3 \4 C B Bce +");
      byte myArray[7] = {0, 2, 4, 6, 8, 10, 12};
      byte i;
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(38 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(38 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }

      {
        lcd.setCursor(1, 3);
        lcd.print(" ");
      }
      {
        lcd.setCursor(3, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(38) == 0 or EEPROM_read_byte(39) == 0 or EEPROM_read_byte(40) == 0 or EEPROM_read_byte(41) == 0 or EEPROM_read_byte(42) == 0 or EEPROM_read_byte(43) == 0 or EEPROM_read_byte(44) == 0) {
        lcd.setCursor(15, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(38) == 1 && EEPROM_read_byte(39) == 1 && EEPROM_read_byte(40) == 1 && EEPROM_read_byte(41) == 1 && EEPROM_read_byte(42) == 1 && EEPROM_read_byte(43) == 1 && EEPROM_read_byte(44) == 1) {
        lcd.setCursor(15, 3);
        lcd.print(char(94));
      }
      lcd.setCursor(17, 3);
      lcd.print("<->");

      lcd.blink();
      if (button == 5 && flag == 1) posic++;
      if (button == 2 && flag == 1) posic--;
      if (posic == 0)
      {
        lcd.setCursor(19, 0);
        if (button == 3 && flag == 1)
        { if (Timer3 < 1)  Timer3++;
          else
            Timer3 = 0;
          EEPROM_write_byte(14, Timer2);
        }
        if (button == 4 && flag == 1)
        { if (Timer3 > 0)  Timer3--;
          else
            Timer3 = 1;
          EEPROM_write_byte(14, Timer3);
        }
      }
      if (posic == 1)
      {
        lcd.setCursor(5, 1);
        if (button == 3 && flag == 1)
        { if (TstartHour3 < 23)  TstartHour3++;
          else
            TstartHour3 = 0;
          EEPROM_write_byte(15, TstartHour3);
        }
        if (button == 4 && flag == 1)
        { if (TstartHour3 > 0)  TstartHour3--;
          else
            TstartHour3 = 23;
          EEPROM_write_byte(15, TstartHour3);
        }
      }
      if (posic == 2)
      {
        lcd.setCursor(8, 1);
        if (button == 3 && flag == 1)
        { if (TstartMinute3 < 59)  TstartMinute3++;
          else
            TstartMinute3 = 0;
          EEPROM_write_byte(16, TstartMinute3);
        }
        if (button == 4 && flag == 1)
        { if (TstartMinute3 > 0)  TstartMinute3--;
          else
            TstartMinute3 = 59;
          EEPROM_write_byte(16, TstartMinute3);
        }
      }
      if (posic == 3)
      {
        lcd.setCursor(16, 1);
        if (button == 3 && flag == 1)
        { if (TstopHour3 < 23)  TstopHour3++;
          else
            TstopHour3 = 0;
          EEPROM_write_byte(17, TstopHour3);
        }
        if (button == 4 && flag == 1)
        { if (TstopHour3 > 0)  TstopHour3--;
          else
            TstopHour3 = 23;
          EEPROM_write_byte(17, TstopHour3);
        }
      }
      if (posic == 4)
      {
        lcd.setCursor(19, 1);
        if (button == 3 && flag == 1)
        { if (TstopMinute3 < 59)  TstopMinute3++;
          else
            TstopMinute3 = 0;
          EEPROM_write_byte(18, TstopMinute3);
        }
        if (button == 4 && flag == 1)
        { if (TstopMinute3 > 0)  TstopMinute3--;
          else
            TstopMinute3 = 59;
          EEPROM_write_byte(18, TstopMinute3);
        }
      }
      if (posic == 5) //устанавливаем дни недели для будильника "Все сразу"
      {
        lcd.setCursor(15, 2);
        if (button == 3 && flag == 1)
        {
          if (Tday < 1)  Tday++;
          else
            Tday = 0;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(38 + i, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (Tday > 0)  Tday--;
          else
            Tday = 1;

          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(38 + i, Tday);
        }
      }
      if (posic == 6) //устанавливаем будильника ПH
      {
        lcd.setCursor(0, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(38) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(38, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(38) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(38, Tday);
        }
      }
      if (posic == 7) //устанавливаем для будильника BT
      {
        lcd.setCursor(2, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(39) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(39, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(39) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(39, Tday);
        }
      }
      if (posic == 8) //устанавливаем для будильника СР
      {
        lcd.setCursor(4, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(40) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(40, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(40) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(40, Tday);
        }
      }
      if (posic == 9) //устанавливаем для будильника ЧТ
      {
        lcd.setCursor(6, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(41) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(41, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(41) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(41, Tday);
        }
      }
      if (posic == 10) //устанавливаем для будильника ПТ
      {
        lcd.setCursor(8, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(42) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(42, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(42) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(42, Tday);
        }
      }
      if (posic == 11) //устанавливаем для будильника СБ
      {
        lcd.setCursor(10, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(43) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(43, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(43) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(43, Tday);
        }
      }
      if (posic == 12) //устанавливаем для будильника ВС
      {
        lcd.setCursor(12, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(44) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(44, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(44) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(44, Tday);
        }
      }
      if (posic == 13) posic = 0; //возврат в начало
    }

    if (regim == 4) // режим Установка Времени Таймера 4 
    {
      Timer4 = EEPROM_read_byte(19);
      lcd.setCursor(0, 0);
      lcd.print("[4]\6CT TA\7MEP 4- ");
      if (Timer4 == 0) lcd.print("B\2K");
      if (Timer4 == 1) lcd.print("BK ");
      TstartHour4 = EEPROM_read_byte(20);
      TstartMinute4 = EEPROM_read_byte(21);
      TstopHour4 = EEPROM_read_byte(22);
      TstopMinute4 = EEPROM_read_byte(23);

      //   Button_read(); //читаем кнопки // проверяем нажата ли кнопка
      lcd.setCursor(0, 1);
      lcd.print("BK\5=");
      //lcd.setCursor(4,1);
      if (TstartHour4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartHour4);
      lcd.print(":");
      if (TstartMinute4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstartMinute4);
      lcd.print(" ");
      lcd.setCursor(10, 1);
      lcd.print("B\2K\5=");
      lcd.setCursor(15, 1);
      if (TstopHour4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopHour4);
      lcd.print(":");
      if (TstopMinute4 < 10) {
        lcd.print("0");
      }
      lcd.print(TstopMinute4);
      lcd.setCursor(0, 2);
      lcd.print("\4 B C \3 \4 C B Bce +");
      byte myArray[7] = {0, 2, 4, 6, 8, 10, 12};
      byte i;
      for (i = 0; i < 7; i++)
      {
        if (EEPROM_read_byte(45 + i) == 1) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(char(94));
        }
        if (EEPROM_read_byte(45 + i) == 0) {
          lcd.setCursor(myArray[i], 3);
          lcd.print(" ");
        }
      }

      {
        lcd.setCursor(1, 3);
        lcd.print(" ");
      }
      {
        lcd.setCursor(3, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(45) == 0 or EEPROM_read_byte(46) == 0 or EEPROM_read_byte(47) == 0 or EEPROM_read_byte(48) == 0 or EEPROM_read_byte(49) == 0 or EEPROM_read_byte(50) == 0 or EEPROM_read_byte(51) == 0) {
        lcd.setCursor(15, 3);
        lcd.print(" ");
      }
      if (EEPROM_read_byte(45) == 1 && EEPROM_read_byte(46) == 1 && EEPROM_read_byte(47) == 1 && EEPROM_read_byte(48) == 1 && EEPROM_read_byte(49) == 1 && EEPROM_read_byte(50) == 1 && EEPROM_read_byte(51) == 1) {
        lcd.setCursor(15, 3);
        lcd.print(char(94));
      }
      lcd.setCursor(17, 3);
      lcd.print("<->");

      lcd.blink();
      if (button == 5 && flag == 1) posic++;
      if (button == 2 && flag == 1) posic--;
      if (posic == 0)
      {
        lcd.setCursor(19, 0);
        if (button == 3 && flag == 1)
        { if (Timer4 < 1)  Timer4++;
          else
            Timer4 = 0;
          EEPROM_write_byte(19, Timer4);
        }
        if (button == 4 && flag == 1)
        { if (Timer4 > 0)  Timer4--;
          else
            Timer4 = 1;
          EEPROM_write_byte(19, Timer4);
        }
      }
      if (posic == 1)
      {
        lcd.setCursor(5, 1);
        if (button == 3 && flag == 1)
        { if (TstartHour4 < 23)  TstartHour4++;
          else
            TstartHour4 = 0;
          EEPROM_write_byte(20, TstartHour4);
        }
        if (button == 4 && flag == 1)
        { if (TstartHour4 > 0)  TstartHour4--;
          else
            TstartHour4 = 23;
          EEPROM_write_byte(20, TstartHour);
        }
      }
      if (posic == 2)
      {
        lcd.setCursor(8, 1);
        if (button == 3 && flag == 1)
        { if (TstartMinute4 < 59)  TstartMinute4++;
          else
            TstartMinute4 = 0;
          EEPROM_write_byte(21, TstartMinute4);
        }
        if (button == 4 && flag == 1)
        { if (TstartMinute4 > 0)  TstartMinute4--;
          else
            TstartMinute4 = 59;
          EEPROM_write_byte(21, TstartMinute4);
        }
      }
      if (posic == 3)
      {
        lcd.setCursor(16, 1);
        if (button == 3 && flag == 1)
        { if (TstopHour4 < 23)  TstopHour4++;
          else
            TstopHour4 = 0;
          EEPROM_write_byte(22, TstopHour4);
        }
        if (button == 4 && flag == 1)
        { if (TstopHour4 > 0)  TstopHour4--;
          else
            TstopHour4 = 23;
          EEPROM_write_byte(22, TstopHour4);
        }
      }
      if (posic == 4)
      {
        lcd.setCursor(19, 1);
        if (button == 3 && flag == 1)
        { if (TstopMinute4 < 59)  TstopMinute4++;
          else
            TstopMinute4 = 0;
          EEPROM_write_byte(23, TstopMinute4);
        }
        if (button == 4 && flag == 1)
        { if (TstopMinute4 > 0)  TstopMinute4--;
          else
            TstopMinute4 = 59;
          EEPROM_write_byte(23, TstopMinute4);
        }
      }
      if (posic == 5) //устанавливаем дни недели для будильника "Все сразу"
      {
        lcd.setCursor(15, 2);
        if (button == 3 && flag == 1)
        {
          if (Tday < 1)  Tday++;
          else
            Tday = 0;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(45 + i, Tday);

        }
        if (button == 4 && flag == 1)
        {
          if (Tday > 0)  Tday--;
          else
            Tday = 1;
          byte i;
          for (i = 0; i < 7; i++)  EEPROM_write_byte(45 + i, Tday);

        }
      }
      if (posic == 6) //устанавливаем будильника ПH
      {
        lcd.setCursor(0, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(45) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(45, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(45) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(45, Tday);
        }
      }
      if (posic == 7) //устанавливаем для будильника BT
      {
        lcd.setCursor(2, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(46) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(46, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(46) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(46, Tday);
        }
      }
      if (posic == 8) //устанавливаем для будильника СР
      {
        lcd.setCursor(4, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(47) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(47, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(47) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(47, Tday);
        }
      }
      if (posic == 9) //устанавливаем для будильника ЧТ
      {
        lcd.setCursor(6, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(48) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(48, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(48) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(48, Tday);
        }
      }
      if (posic == 10) //устанавливаем для будильника ПТ
      {
        lcd.setCursor(8, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(49) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(49, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(49) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(49, Tday);
        }
      }
      if (posic == 11) //устанавливаем для будильника СБ
      {
        lcd.setCursor(10, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(50) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(50, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(50) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(50, Tday);
        }
      }
      if (posic == 12) //устанавливаем для будильника ВС
      {
        lcd.setCursor(12, 2);
        if (button == 3 && flag == 1)
        {
          if (EEPROM_read_byte(51) < 1)  Tday++;
          else
            Tday = 0;
          EEPROM_write_byte(51, Tday);
        }
        if (button == 4 && flag == 1)
        {
          if (EEPROM_read_byte(51) > 0)  Tday--;
          else
            Tday = 1;
          EEPROM_write_byte(51, Tday);
        }
      }

      if (posic == 13) posic = 0; //возврат в начало
    }

    if (regim == 5) //Режим установки часов
    {
      lcd.setCursor(0, 0);
      lcd.print("[5]\6CT \3ACOB        ");
      lcd.setCursor(0, 1);
      if (t.date < 10) {
        lcd.print("0");
      }
      lcd.print(t.date);
      lcd.print("/");
      if (t.mon < 10) {
        lcd.print("0");
      }
      lcd.print(t.mon);
      lcd.print("/");
      lcd.print(t.year);
      lcd.print("  ");
      if (t.dow == 1) lcd.print("\4H      ");
      if (t.dow == 2) lcd.print("BT      ");
      if (t.dow == 3) lcd.print("CP      ");
      if (t.dow == 4) lcd.print("\3T      ");
      if (t.dow == 5) lcd.print("\4T      ");
      if (t.dow == 6) {
        lcd.print("C");
        lcd.write(0);
        lcd.print("      ");
      }
      if (t.dow == 7) lcd.print("BC      ");
      lcd.setCursor(0, 2);
      if (t.hour < 10) {
        lcd.print("0");
      }
      lcd.print(t.hour);
      lcd.print(":");
      if (t.min < 10) {
        lcd.print("0");
      }
      lcd.print(t.min);
      lcd.print(":");
      if (t.sec < 10) {
        lcd.print("0");
      }
      lcd.print(t.sec);
      lcd.setCursor(8, 2);
      lcd.print("          + ");
      lcd.setCursor(0, 3);
      lcd.print("MEH\1             <->");
      lcd.blink();

      if (button == 5 && flag == 1) posic++;
      if (button == 2 && flag == 1) posic--;
      if (posic == 0)
      {
        lcd.setCursor(1, 1);
        if (button == 3 && flag == 1)
        { if (t.date < 31)  t.date++;
          else
            t.date = 0;
          rtc.setDate(t.date, t.mon, t.year);
          timeDS3231();
        }
        if (button == 4 && flag == 1)
        { if (t.date > 1)  t.date--;
          else
            t.date = 31;
          rtc.setDate(t.date, t.mon, t.year);
          timeDS3231();
        }
      }

      if (posic == 1)
      {
        lcd.setCursor(4, 1);
        if (button == 3 && flag == 1)
        { if (t.mon < 12)  t.mon++;
          else
            t.mon = 1;
          rtc.setDate(t.date, t.mon, t.year);
          timeDS3231();
        }
        if (button == 4 && flag == 1)
        { if (t.mon > 1)  t.mon--;
          else
            t.mon = 12;
          rtc.setDate(t.date, t.mon, t.year);
          timeDS3231();
        }
      }

      if (posic == 2)
      {
        lcd.setCursor(9, 1);
        if (button == 3 && flag == 1)
        { if (t.year < 2100)  t.year++;
          else
            t.year = 2000;
          rtc.setDate(t.date, t.mon, t.year);
          timeDS3231();
        }
        if (button == 4 && flag == 1)
        { if (t.year > 2000)  t.year--;
          else
            t.year = 2100;
          rtc.setDate(t.date, t.mon, t.year);
          timeDS3231();
        }
      }

      if (posic == 3)
      {
        lcd.setCursor(13, 1);
        if (button == 3 && flag == 1)
        { if (t.dow < 7)  t.dow++;
          else
            t.dow = 1;
          rtc.setDOW(t.dow);
          timeDS3231();
        }
        if (button == 4 && flag == 1)
        { if (t.dow > 1)  t.dow--;
          else
            t.dow = 7;
          rtc.setDOW(t.dow);
          timeDS3231();
        }
      }
      if (posic == 4)
      {
        lcd.setCursor(1, 2);
        if (button == 3 && flag == 1)
        { if (t.hour < 23)  t.hour++;
          else
            t.hour = 0;
          rtc.setTime(t.hour, t.min, t.sec);
          timeDS3231();
        }
        if (button == 4 && flag == 1)
        { if (t.hour > 0)  t.hour--;
          else
            t.hour = 23;
          rtc.setTime(t.hour, t.min, t.sec);
          timeDS3231();
        }
      }
      if (posic == 5)
      {
        lcd.setCursor(4, 2);
        if (button == 3 && flag == 1)
        { if (t.min < 59)  t.min++;
          else
            t.min = 0;
          rtc.setTime(t.hour, t.min, t.sec);
          timeDS3231();
        }
        if (button == 4 && flag == 1)
        { if (t.min > 0)  t.min--;
          else
            t.min = 59;
          rtc.setTime(t.hour, t.min, t.sec);
          timeDS3231();
        }
      }
      if (posic == 6) posic = 0;

    }
  }
  while (regim < 6); //////////////////////
  lcd.clear();
  lcd.noBlink();
  regim = 0;
  posic = 0;
}

void TimePrint()
{
  lcd.setCursor(0, 0);
  if (t.dow == 1) lcd.print("\4H ");
  if (t.dow == 2) lcd.print("BT ");
  if (t.dow == 3) lcd.print("CP ");
  if (t.dow == 4) lcd.print("\3T ");
  if (t.dow == 5) lcd.print("\4T ");
  if (t.dow == 6) {
    lcd.print("C");
    lcd.write(0);
    lcd.print(" ");
  }
  if (t.dow == 7) lcd.print("  BC ");
  if (t.hour < 10) lcd.print('0');
  lcd.print(t.hour, DEC);
  lcd.print(':');
  if (t.min < 10) lcd.print('0');
  lcd.print(t.min, DEC);
//  lcd.print(":");
//  if (t.sec < 10) lcd.print('0');
//  lcd.print(t.sec, DEC);
  lcd.print(" ");
  if (t.date < 10) lcd.print('0');
  lcd.print(t.date, DEC);
  lcd.print(".");
  if (t.mon < 10) lcd.print('0');
  lcd.print(t.mon, DEC);
  lcd.print(".");
//  if (t.year < 10) lcd.print('0');
  lcd.print(t.year, DEC);
  lcd.print(" ");
}

//=========== Обработки печати и вывода на дисплейчик (Влажности воздуха, температуры воздуха)
void printDin()
{
  lcd.setCursor(7, 1);
  lcd.print("H%=");
  if (HumIn < 10) lcd.print('0');
  lcd.print(int(HumIn));
  lcd.print(" ");
  lcd.setCursor(0, 1);
  lcd.print(" t");
  lcd.print((char)223);
  lcd.print("=");
  if (TIn < 10) lcd.print('0');
  lcd.print(int(TIn));
  lcd.print(" ");
}
//=========== Обработки печати и вывода на дисплейчик СТАТИКИ
void printStat ()
{
  lcd.setCursor(13, 1);
  lcd.print("T.\4O\5>>");
  lcd.setCursor(0, 2);
  lcd.print("\4O\5  1   2   3   4  ");
  lcd.setCursor(0, 3);
  lcd.print("    [");
  lcd.setCursor(6, 3);
  lcd.print("] ");
  lcd.setCursor(8, 3);
  lcd.print("[");
  lcd.setCursor(10, 3);
  lcd.print("] ");
  lcd.setCursor(12, 3);
  lcd.print("[");
  lcd.setCursor(14, 3);
  lcd.print("] ");
  lcd.setCursor(16, 3);
  lcd.print("[");
  lcd.setCursor(18, 3);
  lcd.print("] ");
}

void loop()
{
  timeDS3231();
  TInGet();
  HumInGet();
  Irrigation();
  StaticButton();
  TimePrint();
  printDin();
  printStat();
}

 

vvadim
Offline
Зарегистрирован: 23.05.2012

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

простыню чужого кода более 2000 строк никто смотреть не будет.