#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include "flprogUtilites.h"
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
Adafruit_ADS1115 _ADS1x15_1_instance(0x48);
struct UB_190980469
{
    bool ubo_112544725 = 0;
    bool _swi1 = 0;
    bool _trgr2 = 0;
    bool _trgr1 = 0;
}
;
UB_190980469 UB_190980469_Instance1;
float UB_190980469_ubi_230406663 = 0.00;
float UB_190980469_ubi_80263719 = 0.00;
float UB_190980469_ubi_246319478 = 0.00;
bool UB_190980469_ubi_76699891 = 0;
struct _poligonInexes
{
    int minIndex;
    int maxIndex;
}
;
int _Poligon_InArray_2[26] = {0, 0.625, 1.875, 3.625, 5.875, 8.625, 11.875, 15.75, 20.0, 24.875, 30.125, 35.875, 42.0, 48.625, 55.625, 63.1, 70.875, 79.125, 87.75, 96.625, 105.875, 115.5, 125.5, 135.625, 146.125, 156.875};
int _Poligon_OutArray_2[26] = {0, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300};
int _Poligon_InArray_4[18] = {-273, -239, -193, -148, -45, 602, 1420, 2352, 3364, 4420, 5534, 6693, 7898, 9148, 10455, 11795, 13170, 14580};
int _Poligon_OutArray_4[18] = {-50, -40, -30, -20, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300};
int _Poligon_InArray_6[33] = {-4.375, -4.25, -4.0, -3.375, -2.375, -1.25, 0, 1.375, 2.75, 4.25, 5.875, 7.625, 9.375, 11.125, 13, 14.875, 16.75, 18.625, 20.625, 22.5, 24.5, 26.5, 28.5, 30.375, 32.375, 34.25, 36.25, 38.125, 40.125, 42, 43.875, 45.625, 47};
int _Poligon_OutArray_6[33] = {-270, -250, -200, -150, -100, -50, 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300};
int _Poligon_InArray_3[33] = {-6.5, -6.375, -5.875, -4.875, -3.5, -1.875, 0, 2.0, 4.125, 6.125, 8.125, 10.125, 12.25, 14.25, 16.375, 18.5, 20.625, 22.75, 24.875, 27, 29.125, 31.25, 33.25, 35.25, 37.375, 39.25, 41.25, 43.25, 45.125, 47, 48.875, 50.625, 52.375};
int _Poligon_OutArray_3[33] = {-270, -250, -200, -150, -100, -50, 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300};
int _Poligon_InArray_1[31] = {-8.625, -8.625, -7.875, -6.5, -4.625, -2.375, 0, 2.625, 5.25, 8.0, 10.75, 13.5, 16.375, 19.125, 21.875, 24.625, 27.375, 30.25, 33.125, 36, 39.125, 42.25, 45.5, 48.75, 51.875, 54.875, 57.875, 60.875, 63.75, 66.625, 69.5};
int _Poligon_OutArray_1[31] = {-270, -250, -200, -150, -100, -50, 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200};
int _Poligon_InArray_5[25] = {-9.875, -9.75, -9.5, -9.25, -8.875, -8.25, -7.625, -7.25, -6.875, -6.125, -5.25, -4.25, -3.25, -2.75, -1.75, -1.125, 0, 1.25, 1.75, 3.0, 3.625, 4.375, 5.0, 5.625, 6.375};
int _Poligon_OutArray_5[25] = {-270, -250, -230, -220, -200, -180, -160, -150, -140, -120, -100, -80, -60, -50, -30, -20, 0, 20, 30, 50, 60, 70, 80, 90, 100};
const int _menuParametrsArray[]  PROGMEM =  {1, 8, 1, 0, 0, 0, 2, 4, 1, 0, 7, 0, 2, 8, 2, 0, 0, 0, 3, 5, 1, 0, 8, 0, 3, 3, 2, 0, 0, 0, 9, 10, 1, 8, 2, 0, 4, 3, 6, 0, 0, 0, 9, 10, 1, 8, 6, 0, 5, 3, 3, 0, 0, 0, 9, 10, 1, 8, 3, 0, 6, 3, 1, 0, 0, 0, 9, 10, 1, 8, 1, 0, 7, 3, 5, 0, 0, 0, 9, 10, 1, 8, 5, 0, 8, 3, 4, 0, 0, 0, 9, 10, 1, 8, 4, 0};
bool _menuValueArray_bool[6];
const bool _menuConstantValuesArray_bool[]  PROGMEM =  {1};
float _menuValueArray_float[2];
const float _menuConstantValuesArray_float[]  PROGMEM =  {10, 1000, 900, 100, 50};
const char _flprogMenuNameString1[] PROGMEM = "TYPE R";
const char _flprogMenuNameString2[] PROGMEM = "TYPE K";
const char _flprogMenuNameString3[] PROGMEM = "TYPE J";
const char _flprogMenuNameString4[] PROGMEM = "TYPE N";
const char _flprogMenuNameString5[] PROGMEM = "TYP E";
const char _flprogMenuNameString6[] PROGMEM = "TYPE B";
const char _flprogMenuNameString7[] PROGMEM = "TOFF";
const char _flprogMenuNameString8[] PROGMEM = "TON";
const char _flprogMenuNameString9[] PROGMEM = "YES";
const char _flprogMenuNameString10[] PROGMEM = "NO";
const char* const _flprogMenuStringsArray[] PROGMEM = { _flprogMenuNameString1,  _flprogMenuNameString2,  _flprogMenuNameString3,  _flprogMenuNameString4,  _flprogMenuNameString5,  _flprogMenuNameString6,  _flprogMenuNameString7,  _flprogMenuNameString8,  _flprogMenuNameString9,  _flprogMenuNameString10};
struct _menuItemStricture 
{
     int startInArrayIndex;
}
;
struct _menuMainStricture 
{
    String menuName;
    int startIndex;
    int stopIndex;
    bool isSwitchMenuAroundRing;
    _menuItemStricture  currentItem;
}
;
_menuItemStricture _MenuItems[8];
_menuMainStricture _MainMenus[1];
bool _gtv1;
bool _gtv2;
float _swi10;
String _swi29;
String _swi6;
bool _swi24;
String _swi28;
bool _swi23;
String _swi15;
float _swi20;
int _disp1oldLength = 0;
int _disp2oldLength = 0;
float _swi27;
bool _bounseInputD4S = 0;
bool _bounseInputD4O = 0;
unsigned long _bounseInputD4P = 0UL;
float _swi2;
int _disp4oldLength = 0;
bool _bounseInputD1S = 0;
bool _bounseInputD1O = 0;
unsigned long _bounseInputD1P = 0UL;
float _swi8;
String _swi19;
float _swi4;
bool _bounseInputD3S = 0;
bool _bounseInputD3O = 0;
unsigned long _bounseInputD3P = 0UL;
float _swi11;
int _disp3oldLength = 0;
bool _bounseInputD7S = 0;
bool _bounseInputD7O = 0;
unsigned long _bounseInputD7P = 0UL;
float _swi7;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
String _swi18;
bool _MenuBlock_109232683_AGO = 0;
bool _MenuBlock_109232683_AMO_91185362 = 0;
bool _MenuBlock_109232683_AMO_195524378 = 0;
String _MenuBlock_109232683_MNO;
String _MenuBlock_109232683_VNO;
bool _MenuBlock_109232683_OEIS = 0;
bool _MenuBlock_109232683_OMUIS = 0;
bool _MenuBlock_109232683_OMDIS = 0;
bool _MenuBlock_109232683_OVUIS = 0;
bool _MenuBlock_109232683_OVDIS = 0;
bool _MenuBlock_109232683_AMMO = 0;
String _MenuBlock_109232683_NPMO;
float _swi26;
bool _trgt1 = 0;
bool _trgt1I = 0;
String _swi16;
float _swi21;
String _swi9;
bool _bounseInputD6S = 0;
bool _bounseInputD6O = 0;
unsigned long _bounseInputD6P = 0UL;
String _swi14;
float _swi5;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
String _swi17;
float _swi1;
String _swi22;
String _swi12;
String _swi25;
bool _trgt2 = 0;
bool _trgt2I = 0;
float _ADS1x15_1_Output_5 = 0.00;
bool _ADS1x15_1_isNeedRequest_5 = 0;
unsigned long _ADS1x15_1_StartTime_5 = 0UL;
float _ADS1x15_1_Output_6 = 0.00;
bool _ADS1x15_1_isNeedRequest_6 = 0;
unsigned long _ADS1x15_1_StartTime_6 = 0UL;
bool _bounseInputD5S = 0;
bool _bounseInputD5O = 0;
unsigned long _bounseInputD5P = 0UL;
String _swi13;
String _swi3;
bool _tempVariable_bool;
int _tempVariable_int;
void setup()
{
    pinMode(3, INPUT_PULLUP);
    pinMode(4, INPUT_PULLUP);
    pinMode(5, INPUT_PULLUP);
    pinMode(6, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);
    pinMode(7, INPUT_PULLUP);
    pinMode(2, OUTPUT);
    digitalWrite(2, 0);
    Wire.begin();
    delay(10);
    if(((readByteFromEEPROM(0, 0, 0x0))) != 68) 
    {
        (updateByteToEEPROM(0, 0, 0x0, (68)));
        (updateBooleanToEEPROM(1, 0, 0x0, (0)));
        (updateBooleanToEEPROM(1, 1, 0x0, (0)));
        (updateBooleanToEEPROM(1, 2, 0x0, (0)));
        (updateBooleanToEEPROM(1, 3, 0x0, (0)));
        (updateBooleanToEEPROM(1, 4, 0x0, (0)));
        (updateBooleanToEEPROM(1, 5, 0x0, (0)));
        (updateFloatToEEPROM(2, 0, 0x0, (100)));
        (updateFloatToEEPROM(6, 0, 0x0, (30)));
    }
    _lcd1.init();
    _lcd1.backlight();
    _bounseInputD4O =    digitalRead(4);
    _bounseInputD6O =    digitalRead(6);
    _bounseInputD1O =    digitalRead(1);
    _bounseInputD7O =    digitalRead(7);
    _bounseInputD3O =    digitalRead(3);
    _bounseInputD5O =    digitalRead(5);
    _ADS1x15_1_instance.setGain(GAIN_SIXTEEN);
    _ADS1x15_1_instance.begin();
    _MenuItems[0].startInArrayIndex = 0;
    _MenuItems[1].startInArrayIndex = 12;
    _MenuItems[2].startInArrayIndex = 24;
    _MenuItems[3].startInArrayIndex = 36;
    _MenuItems[4].startInArrayIndex = 48;
    _MenuItems[5].startInArrayIndex = 60;
    _MenuItems[6].startInArrayIndex = 72;
    _MenuItems[7].startInArrayIndex = 84;
    _MainMenus[0].menuName = "Menu ";
    _MainMenus[0].startIndex = 1;
    _MainMenus[0].isSwitchMenuAroundRing = 1;
    _MainMenus[0].stopIndex = 8;
    _MainMenus[0].currentItem = _MenuItems[0];
    _menuValueArray_bool[0] = (readBooleanFromEEPROM(1, 0, 0x0));
    _menuValueArray_bool[1] = (readBooleanFromEEPROM(1, 1, 0x0));
    _menuValueArray_bool[2] = (readBooleanFromEEPROM(1, 2, 0x0));
    _menuValueArray_bool[3] = (readBooleanFromEEPROM(1, 3, 0x0));
    _menuValueArray_bool[4] = (readBooleanFromEEPROM(1, 4, 0x0));
    _menuValueArray_bool[5] = (readBooleanFromEEPROM(1, 5, 0x0));
    _menuValueArray_float[0] = (readFloatFromEEPROM(2, 0, 0x0));
    _menuValueArray_float[1] = (readFloatFromEEPROM(6, 0, 0x0));
}
void loop()
{
    if (_isNeedClearDisp1) 
    {
        _lcd1.clear();
        _isNeedClearDisp1= 0;
    }
    bool  _bounceInputTmpD5 =  (digitalRead (5));
    if (_bounseInputD5S)
    {
        if (millis() >= (_bounseInputD5P + 40))
        {
            _bounseInputD5O= _bounceInputTmpD5;
            _bounseInputD5S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD5 != _bounseInputD5O)
        {
            _bounseInputD5S=1;
            _bounseInputD5P = millis();
        }
    }
    bool  _bounceInputTmpD4 =  (digitalRead (4));
    if (_bounseInputD4S)
    {
        if (millis() >= (_bounseInputD4P + 40))
        {
            _bounseInputD4O= _bounceInputTmpD4;
            _bounseInputD4S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD4 != _bounseInputD4O)
        {
            _bounseInputD4S=1;
            _bounseInputD4P = millis();
        }
    }
    bool  _bounceInputTmpD7 =  (digitalRead (7));
    if (_bounseInputD7S)
    {
        if (millis() >= (_bounseInputD7P + 40))
        {
            _bounseInputD7O= _bounceInputTmpD7;
            _bounseInputD7S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD7 != _bounseInputD7O)
        {
            _bounseInputD7S=1;
            _bounseInputD7P = millis();
        }
    }
    bool  _bounceInputTmpD6 =  (digitalRead (6));
    if (_bounseInputD6S)
    {
        if (millis() >= (_bounseInputD6P + 40))
        {
            _bounseInputD6O= _bounceInputTmpD6;
            _bounseInputD6S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD6 != _bounseInputD6O)
        {
            _bounseInputD6S=1;
            _bounseInputD6P = millis();
        }
    }
    bool  _bounceInputTmpD3 =  (digitalRead (3));
    if (_bounseInputD3S)
    {
        if (millis() >= (_bounseInputD3P + 40))
        {
            _bounseInputD3O= _bounceInputTmpD3;
            _bounseInputD3S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD3 != _bounseInputD3O)
        {
            _bounseInputD3S=1;
            _bounseInputD3P = millis();
        }
    }
    bool  _bounceInputTmpD1 =  (digitalRead (1));
    if (_bounseInputD1S)
    {
        if (millis() >= (_bounseInputD1P + 40))
        {
            _bounseInputD1O= _bounceInputTmpD1;
            _bounseInputD1S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD1 != _bounseInputD1O)
        {
            _bounseInputD1S=1;
            _bounseInputD1P = millis();
        }
    }
    //Плата:1
    if (!(_bounseInputD5O)) 
    {
         if (! _gen1I) 
        {
            _gen1I = 1;
            _gen1O = 1;
            _gen1P = millis();
        }
    }
     else 
    {
        _gen1I = 0 ;
        _gen1O= 0;
    }
    if (_gen1I) 
    {
          if (flprog::isTimer (_gen1P , 330)) 
        {
             _gen1P = millis();
            _gen1O = ! _gen1O;
        }
    }
    bool  _tmp1 = !(_bounseInputD1O);
    if (_tmp1)  
    {
         if (! _trgt1I) _trgt1 = ! _trgt1;
    }
    _trgt1I = _tmp1;
    if (_trgt1) 
    {
        _tempVariable_bool  =  1;
        if (! _MenuBlock_109232683_OEIS) 
        {
            _MenuBlock_109232683_OEIS = 1;
        }
        _tempVariable_int = pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+10]);
        _MenuBlock_109232683_MNO = _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[_tempVariable_int - 1])));
        _MenuBlock_109232683_VNO = _menuOutputValueString (0);
        _MenuBlock_109232683_AMO_91185362 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 1;
        _MenuBlock_109232683_AMO_195524378 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 2;
        _MenuBlock_109232683_AGO = (pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+1])) == 0;
        _MenuBlock_109232683_AMMO = (pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+5])) == 0;
        if((pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex) +5]))== 0) 
        {
            _MenuBlock_109232683_NPMO = (_MainMenus[0]).menuName;
        }
         else 
        {
            _tempVariable_int  =  pgm_read_byte(&_menuParametrsArray[(((_MainMenus[0]).currentItem).startInArrayIndex)+5]);
            _MenuBlock_109232683_NPMO = _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[(pgm_read_byte(&_menuParametrsArray[((_MenuItems[_tempVariable_int - 1]).startInArrayIndex)+10]))  - 1])));
        }
    }
     else 
    {
        _tempVariable_bool  =  0;
        if (_MenuBlock_109232683_OEIS)
        {
            _MenuBlock_109232683_OEIS = 0;
        }
        _MenuBlock_109232683_AMO_91185362 = 0;
        _MenuBlock_109232683_AMO_195524378 = 0;
        _MenuBlock_109232683_AGO = 0;
        _MenuBlock_109232683_AMMO = 0;
        _MenuBlock_109232683_NPMO = "";
        _MenuBlock_109232683_MNO = "";
        _MenuBlock_109232683_VNO = "";
    }
    if(!(_bounseInputD3O)) 
    {
         if (! _MenuBlock_109232683_OMUIS) 
        {
            _MenuBlock_109232683_OMUIS = 1;
            if(_tempVariable_bool)
            {
                  _menuUpEvents(0);
            }
        }
    }
     else 
    {
        _MenuBlock_109232683_OMUIS = 0;
    }
    if(!(_bounseInputD4O)) 
    {
         if (! _MenuBlock_109232683_OMDIS) 
        {
            _MenuBlock_109232683_OMDIS = 1;
            if(_tempVariable_bool)
            {
                   _menuDownEvents(0);
            }
        }
    }
     else 
    {
        _MenuBlock_109232683_OMDIS = 0;
    }
    if(_gtv1) 
    {
         if (! _MenuBlock_109232683_OVUIS) 
        {
            _MenuBlock_109232683_OVUIS = 1;
            if(_tempVariable_bool)
            {
                _valueUpEvents(0);
                _menuUpdateToEEpromItems();
            }
        }
    }
     else 
    {
        _MenuBlock_109232683_OVUIS = 0;
    }
    if(_gtv2) 
    {
         if (! _MenuBlock_109232683_OVDIS) 
        {
            _MenuBlock_109232683_OVDIS = 1;
            if(_tempVariable_bool)
            {
                _valueDownEvents(0);
                _menuUpdateToEEpromItems();
            }
        }
    }
     else 
    {
        _MenuBlock_109232683_OVDIS = 0;
    }
    if (_trgt1) 
    {
        _dispTempLength1 = ((_MenuBlock_109232683_VNO)).length();
        if (_disp3oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp3oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 1);
        _lcd1.print((_MenuBlock_109232683_VNO));
    }
     else 
    {
        if (_disp3oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp3oldLength = 0;
        }
    }
    if((_ADS1x15_1_StartTime_5 == 0) || (flprog::isTimer(_ADS1x15_1_StartTime_5 , 1000)))
    {
        _ADS1x15_1_StartTime_5 = millis();
        _ADS1x15_1_isNeedRequest_5 = 1;
    }
    if(_ADS1x15_1_isNeedRequest_5) 
    {
        _ADS1x15_1_isNeedRequest_5 = 0;
        _tempVariable_int = _ADS1x15_1_instance.readADC_Differential_0_1();
        _ADS1x15_1_Output_5 = _ads1x15ValueConvert(_tempVariable_int, 5, 0);
    }
    if((_ADS1x15_1_StartTime_6 == 0) || (flprog::isTimer(_ADS1x15_1_StartTime_6 , 1000)))
    {
        _ADS1x15_1_StartTime_6 = millis();
        _ADS1x15_1_isNeedRequest_6 = 1;
    }
    if(_ADS1x15_1_isNeedRequest_6) 
    {
        _ADS1x15_1_isNeedRequest_6 = 0;
        _tempVariable_int = _ADS1x15_1_instance.readADC_Differential_2_3();
        _ADS1x15_1_Output_6 = _ads1x15ValueConvert(_tempVariable_int, 5, 0);
    }
    if((_menuValueArray_bool[4]))
    {
        _swi20=_ADS1x15_1_Output_5;
    }
    else
    {
        _swi20=0;
    }
    if((_menuValueArray_bool[3]))
    {
        _swi26=_ADS1x15_1_Output_5;
    }
    else
    {
        _swi26=0;
    }
    if((_menuValueArray_bool[3]))
    {
        _swi28=(_floatToStringWitRaz(_swi26,3));
    }
    else
    {
        _swi28=String("");
    }
    if((_menuValueArray_bool[4]))
    {
        _swi22=(_floatToStringWitRaz(_swi20,3));
    }
    else
    {
        _swi22=_swi28;
    }
    if((_menuValueArray_bool[0]))
    {
        _swi10=_ADS1x15_1_Output_6;
    }
    else
    {
        _swi10=0;
    }
    if((_menuValueArray_bool[0]))
    {
        _swi19=(_floatToStringWitRaz(_swi10,3));
    }
    else
    {
        _swi19=_swi22;
    }
    if((_menuValueArray_bool[5]))
    {
        _swi7=_ADS1x15_1_Output_6;
    }
    else
    {
        _swi7=0;
    }
    if((_menuValueArray_bool[5]))
    {
        _swi18=(_floatToStringWitRaz(_swi7,3));
    }
    else
    {
        _swi18=_swi19;
    }
    if((_menuValueArray_bool[2]))
    {
        _swi4=_ADS1x15_1_Output_5;
    }
    else
    {
        _swi4=0;
    }
    if((_menuValueArray_bool[2]))
    {
        _swi17=(_floatToStringWitRaz(_swi4,3));
    }
    else
    {
        _swi17=_swi18;
    }
    if((_menuValueArray_bool[1]))
    {
        _swi1=_ADS1x15_1_Output_5;
    }
    else
    {
        _swi1=0;
    }
    if((_menuValueArray_bool[1]))
    {
        _swi16=(_floatToStringWitRaz(_swi1,3));
    }
    else
    {
        _swi16=_swi17;
    }
    if((_menuValueArray_bool[3]))
    {
        _swi27=((_poligon((_swi26), _Poligon_InArray_6, _Poligon_OutArray_6, 33)))*(1.00);
    }
    else
    {
        _swi27=0;
    }
    if((_menuValueArray_bool[4]))
    {
        _swi21=((_poligon((_swi20), _Poligon_InArray_5, _Poligon_OutArray_5, 25)))*(1.00);
    }
    else
    {
        _swi21=_swi27;
    }
    if((_menuValueArray_bool[0]))
    {
        _swi11=((_poligon((_swi10), _Poligon_InArray_4, _Poligon_OutArray_4, 18)))*(1.00);
    }
    else
    {
        _swi11=_swi21;
    }
    if((_menuValueArray_bool[5]))
    {
        _swi8=((_poligon((_swi7), _Poligon_InArray_2, _Poligon_OutArray_2, 26)))*(1.00);
    }
    else
    {
        _swi8=_swi11;
    }
    if((_menuValueArray_bool[2]))
    {
        _swi5=((_poligon((_swi4), _Poligon_InArray_1, _Poligon_OutArray_1, 31)))*(1.00);
    }
    else
    {
        _swi5=_swi8;
    }
    if((_menuValueArray_bool[1]))
    {
        _swi2=((_poligon((_swi1), _Poligon_InArray_3, _Poligon_OutArray_3, 33)))*(1.00);
    }
    else
    {
        _swi2=_swi5;
    }
    UB_190980469_ubi_230406663 = _swi2;
    UB_190980469_ubi_80263719 = (_menuValueArray_float[1]);
    UB_190980469_ubi_246319478 = (_menuValueArray_float[0]);
    UB_190980469_ubi_76699891 = 1;
    _func_UB_190980469(&UB_190980469_Instance1, UB_190980469_ubi_230406663, UB_190980469_ubi_80263719, UB_190980469_ubi_246319478, UB_190980469_ubi_76699891);
    if(!(UB_190980469_Instance1.ubo_112544725))
    {
        _swi14=(_floatToStringWitRaz((_menuValueArray_float[1]),0));
    }
    else
    {
        _swi14=(_floatToStringWitRaz((_menuValueArray_float[0]),0));
    }
    digitalWrite(2, UB_190980469_Instance1.ubo_112544725);
    if(UB_190980469_Instance1.ubo_112544725)
    {
        _swi13=String("TOFF=");
    }
    else
    {
        _swi13=String("TON=");
    }
    bool  _tmp2 = !(_bounseInputD7O);
    if (_tmp2)  
    {
         if (! _trgt2I) _trgt2 = ! _trgt2;
    }
    _trgt2I = _tmp2;
    if(_trgt2)
    {
        _swi15=((_swi16) + (String("  ")) + (String("CALIBR")));
    }
    else
    {
        _swi15=(((_floatToStringWitRaz(((analogRead (0)))/(2.046),0))) + (String("C ")) + (_swi13) + (_swi14) + (String("C")));
    }
    if (!(_trgt1)) 
    {
        _dispTempLength1 = ((_swi15)).length();
        if (_disp4oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp4oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 1);
        _lcd1.print((_swi15));
    }
     else 
    {
        if (_disp4oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp4oldLength = 0;
        }
    }
    if((_menuValueArray_bool[4]))
    {
        _swi29=String("TYPE E");
    }
    else
    {
        _swi29=String("");
    }
    if((_menuValueArray_bool[3]))
    {
        _swi25=String("TYPE N");
    }
    else
    {
        _swi25=_swi29;
    }
    if((_menuValueArray_bool[0]))
    {
        _swi12=String("TYPE R");
    }
    else
    {
        _swi12=_swi25;
    }
    if((_menuValueArray_bool[5]))
    {
        _swi9=String("TYPE B");
    }
    else
    {
        _swi9=_swi12;
    }
    if((_menuValueArray_bool[2]))
    {
        _swi6=String("TYPE J");
    }
    else
    {
        _swi6=_swi9;
    }
    if((_menuValueArray_bool[1]))
    {
        _swi3=String("TYPE K");
    }
    else
    {
        _swi3=_swi6;
    }
    if (!(_trgt1)) 
    {
        _dispTempLength1 = ((((((String("T=")) + ((_floatToStringWitRaz(_swi2,0))) + (String("C")))) + (String("  ")) + (_swi3)))).length();
        if (_disp1oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp1oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 0);
        _lcd1.print((((((String("T=")) + ((_floatToStringWitRaz(_swi2,0))) + (String("C")))) + (String("  ")) + (_swi3))));
    }
     else 
    {
        if (_disp1oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp1oldLength = 0;
        }
    }
    if (_trgt1) 
    {
        _dispTempLength1 = ((_MenuBlock_109232683_MNO)).length();
        if (_disp2oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp2oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 0);
        _lcd1.print((_MenuBlock_109232683_MNO));
    }
     else 
    {
        if (_disp2oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp2oldLength = 0;
        }
    }
    if (!(_bounseInputD6O)) 
    {
         if (! _gen2I) 
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = millis();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
    if (_gen2I) 
    {
          if (flprog::isTimer (_gen2P , 330)) 
        {
             _gen2P = millis();
            _gen2O = ! _gen2O;
        }
    }
    if(((_MenuBlock_109232683_AMO_91185362) || (_MenuBlock_109232683_AMO_195524378)))
    {
        _swi24=_gen2O;
    }
    else
    {
        _swi24=!(_bounseInputD6O);
    }
    _gtv2 = _swi24;
    if(((_MenuBlock_109232683_AMO_91185362) || (_MenuBlock_109232683_AMO_195524378)))
    {
        _swi23=_gen1O;
    }
    else
    {
        _swi23=!(_bounseInputD5O);
    }
    _gtv1 = _swi23;
}
String  _floatToStringWitRaz(float value, int raz)
{
    return String(value,raz);
}
String _readStringFromProgmem (char *string)
{
    String result = String("");
    while (pgm_read_byte(string)!='\0')
    {
        result=result+ char(pgm_read_byte(string));
        	string++;
        	
    }
    return result;
}
void _menuUpEvents (int menuIndex)
{
    int tempIndex = pgm_read_byte(&_menuParametrsArray[((_MainMenus[menuIndex]).currentItem).startInArrayIndex]);
    int parIndex = pgm_read_byte(&_menuParametrsArray[ (((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+5]);
    int parentStartIndex;
    int parentStopIndex;
    if (parIndex == 0) 
    {
        parentStartIndex = (_MainMenus[menuIndex]).startIndex;
        parentStopIndex =(_MainMenus[menuIndex]).stopIndex;
    }
    else 
    {
        parentStartIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex - 1]).startInArrayIndex)+3]);
        parentStopIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+4]);
    }
    if (tempIndex == parentStartIndex) 
    {
        if((_MainMenus[menuIndex]).isSwitchMenuAroundRing) 
        {
            (_MainMenus[menuIndex]).currentItem = _MenuItems[parentStopIndex -1];
            return;
        }
         else
        {
            return;
        }
    }
    (_MainMenus[menuIndex]).currentItem = _MenuItems[tempIndex - 2];
    return;
}
void _menuDownEvents (int menuIndex)
{
    int tempIndex = pgm_read_byte(&_menuParametrsArray[((_MainMenus[menuIndex]).currentItem).startInArrayIndex]);
    int parIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+5]);
    int parentStartIndex;
    int parentStopIndex;
    if (parIndex == 0) 
    {
        parentStartIndex = (_MainMenus[menuIndex]).startIndex;
        parentStopIndex =(_MainMenus[menuIndex]).stopIndex;
    }
    else 
    {
        parentStartIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+3]);
        parentStopIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+4]);
    }
    if (tempIndex == parentStopIndex) 
    {
        if((_MainMenus[menuIndex]).isSwitchMenuAroundRing) 
        {
            (_MainMenus[menuIndex]).currentItem = _MenuItems[parentStartIndex -1];
            return;
        }
         else
        {
            return;
        }
    }
    (_MainMenus[menuIndex]).currentItem = _MenuItems[tempIndex];
    return;
}
void _valueUpEvents (int menuIndex)
{
    int valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
    int itemType = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
    int indexMax = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+6]);
    int indexStep = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+8]);
    if(itemType ==3) 
    {
        _menuValueArray_bool[valIndex - 1 ] = 1;
        return;
    }
    if (itemType == 8) 
    {
        if (! indexMax == 0) 
        {
             if (! (float(pgm_read_float(&_menuConstantValuesArray_float[indexMax -1])) > float(_menuValueArray_float[valIndex -1]))) 
            {
                return;
            }
        }
        _menuValueArray_float[valIndex -1] = _menuValueArray_float[valIndex -1] + (pgm_read_float(&_menuConstantValuesArray_float[indexStep -1]));
    }
}
void _valueDownEvents (int menuIndex)
{
    int valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
    int itemType = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
    int indexMin = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+7]);
    int indexStep = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+8]);
    if(itemType ==3) 
    {
        _menuValueArray_bool[valIndex -1] = 0;
        return;
    }
    if (itemType == 8) 
    {
        if (! indexMin == 0) 
        {
             if (! ((float(pgm_read_float(&_menuConstantValuesArray_float[indexMin - 1]))) < float(_menuValueArray_float[valIndex - 1]))) 
            {
                return;
            }
        }
        _menuValueArray_float[valIndex - 1] = _menuValueArray_float[valIndex - 1] - (pgm_read_float(&_menuConstantValuesArray_float[indexStep - 1]));
    }
}
String _menuOutputValueString (int menuIndex)
{
    int itemType = pgm_read_byte(&_menuParametrsArray[ (((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
    int valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
    int indexMin = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+7]);
    int indexMax = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+6]);
    if(valIndex == 0)
    {
         return "";
    }
    int convFormat = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+9]);
    if(itemType == 3) 
    {
         return _convertBoolean(itemType, convFormat, valIndex, indexMax, indexMin);
    }
    if(itemType == 8) 
    {
         return _convertFloat(itemType, convFormat, valIndex, indexMax, indexMin);
    }
    return "";
}
void _menuUpdateToEEpromItems()
{
    (updateBooleanToEEPROM(1, 0, 0x0, ((_menuValueArray_bool[0]))));
    (updateBooleanToEEPROM(1, 1, 0x0, ((_menuValueArray_bool[1]))));
    (updateBooleanToEEPROM(1, 2, 0x0, ((_menuValueArray_bool[2]))));
    (updateBooleanToEEPROM(1, 3, 0x0, ((_menuValueArray_bool[3]))));
    (updateBooleanToEEPROM(1, 4, 0x0, ((_menuValueArray_bool[4]))));
    (updateBooleanToEEPROM(1, 5, 0x0, ((_menuValueArray_bool[5]))));
    (updateFloatToEEPROM(2, 0, 0x0, ((_menuValueArray_float[0]))));
    (updateFloatToEEPROM(6, 0, 0x0, ((_menuValueArray_float[1]))));
}
String _convertNamber(int itemType, int convFormat, int valIndex, int indexMax, int indexMin)
{
    if (itemType== 8) 
    {
        if (convFormat == 4) 
        {
             return String((_menuValueArray_float[valIndex - 1 ]),DEC);
        }
        if (convFormat == 5) 
        {
             return String((_menuValueArray_float[valIndex - 1]),HEX);
        }
        if (convFormat == 6) 
        {
             return String((_menuValueArray_float[valIndex -1]),BIN);
        }
    }
    return "";
}
String _convertBoolean(int itemType, int convFormat, int valIndex, int indexMax, int indexMin)
{
    if (convFormat == 1) 
    {
         if(_menuValueArray_bool[valIndex -1]) 
        {
            return "1";
        }
         else
        {
             return "0";
        }
    }
    if (convFormat == 2) 
    {
         if(_menuValueArray_bool[valIndex -1]) 
        {
            return "True";
        }
         else
        {
             return "False";
        }
    }
    if (convFormat == 3) 
    {
         if(_menuValueArray_bool[valIndex -1 ]) 
        {
            return "Да";
        }
         else
        {
             return "Нет";
        }
    }
    if(_menuValueArray_bool[valIndex -1]) 
    {
        return _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[indexMax - 1])));
    }
     else 
    {
         return _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[indexMin - 1])));
    }
    return "";
}
String _convertFloat(int itemType, int convFormat, int valIndex , int indexMax, int indexMin)
{
    return String((_menuValueArray_float[valIndex -1]),convFormat);
}
int _poligon(int value, int intArray[], int outArray[], int arraySize)
{
    struct  _poligonInexes indexes;
    indexes = _getPoligonIndexes(value, intArray, arraySize);
    return map(value, intArray[indexes.minIndex], intArray[indexes.maxIndex], outArray[indexes.minIndex], outArray[indexes.maxIndex]);
}
struct  _poligonInexes _getPoligonIndexes(int value, int array[], int arraySize)
{
    struct  _poligonInexes result;
    int i;
    result.minIndex = 0;
    result.maxIndex = 0;
    for (i = 0; i < arraySize; i++) 
    {
        if (array [result.minIndex] > array[i]) 
        {
            result.minIndex = i;
        }
        if (array [result.maxIndex] < array[i]) 
        {
            result.maxIndex = i;
        }
    }
    for (i = 0; i < arraySize; i++)
    {
        if ((array [i] >= value) && (array [result.maxIndex] > array[i])) 
        {
            result.maxIndex = i;
        }
    }
    if (result.maxIndex==0)
    {
        result.minIndex = 0;
        result.maxIndex=1;
    }
     else 
    {
         result.minIndex = result.maxIndex -1;
    }
    return result;
    return result;
}
float _ads1x15ValueConvert(int value, byte gain, bool isVolt)
{
    float temp;
    if(gain == 0) 
    {
         temp = 0.187;
    }
    if(gain == 1) 
    {
         temp = 0.125;
    }
    if(gain == 2) 
    {
         temp = 0.0625;
    }
    if(gain == 3) 
    {
         temp = 0.03125;
    }
    if(gain == 4) 
    {
         temp = 0.01562;
    }
    if(gain == 5) 
    {
         temp = 0.0078125;
    }
    temp = value*temp;
    if(isVolt) 
    {
        temp = temp/1000;
    }
    return temp;
}
byte readByteFromEEPROM(int addres, byte bitAddres, byte chipAddres)
{
    return EEPROM.read(addres);
}
void updateByteToEEPROM(int addres, byte bitAddres, byte chipAddres, byte value)
{
    return EEPROM.update(addres, value);
}
bool readBooleanFromEEPROM(int addres, byte bitAddres, byte chipAddres)
{
    byte temp = readByteFromEEPROM(addres,  bitAddres,  chipAddres);
    return  bitRead(temp, bitAddres);
}
void updateBooleanToEEPROM(int addres, byte bitAddres, byte chipAddres, bool value)
{
    byte temp = readByteFromEEPROM(addres,  bitAddres,  chipAddres);
    bitWrite(temp, bitAddres, value);
    updateByteToEEPROM(addres,  bitAddres,  chipAddres, temp);
}
float readFloatFromEEPROM(int addres, byte bitAddres, byte chipAddres)
{
    byte x[4];
    for(byte i = 0; i < 4; i++) 
    {
         x[i] = readByteFromEEPROM((addres+i),  bitAddres,  chipAddres);
    }
    float *y = (float *)&x;
    return y[0];
}
void updateFloatToEEPROM(int addres, byte bitAddres, byte chipAddres, float value)
{
    byte *x = (byte *)&value;
    for(byte i = 0; i < 4; i++) 
    {
        updateByteToEEPROM((addres+i),  bitAddres,  chipAddres, x[i]);
    }
}
void _func_UB_190980469(struct UB_190980469 *_ubInstans, float ubi_230406663, float ubi_80263719, float ubi_246319478, bool ubi_76699891)
{
    bool ubo_112544725 = _ubInstans->ubo_112544725;
    bool _swi1 = _ubInstans->_swi1;
    bool _trgr2 = _ubInstans->_trgr2;
    bool _trgr1 = _ubInstans->_trgr1;
    if((ubi_230406663) > (ubi_246319478)) _trgr2 = 0;
    if((ubi_230406663) <= (ubi_80263719)) _trgr2 = 1;
    if((ubi_230406663) < (ubi_80263719)) _trgr1 = 0;
    if((ubi_230406663) >= (ubi_246319478)) _trgr1 = 1;
    if(ubi_76699891)
    {
        _swi1=_trgr2;
    }
    else
    {
        _swi1=_trgr1;
    }
    ubo_112544725 = _swi1;
    _ubInstans->ubo_112544725 = ubo_112544725;
    _ubInstans->_swi1 = _swi1;
    _ubInstans->_trgr2 = _trgr2;
    _ubInstans->_trgr1 = _trgr1;
}
