#include "flprogUtilites.h"
#include <LiquidCrystal.h>
#include <TimerOne.h>
LiquidCrystal _lcd1(12, 11, 5, 4, 3, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
int PWM_1_177117968_2;
int PWM_2_177117968_2;
int PWM_3_177117968_2;
float _gtv2 = 0;
bool _gtv1;
float _gtv3;
bool _gtv4;
bool _tim4I = 0;
bool _tim4O = 0;
unsigned long _tim4P = 0UL;
bool _tim1I = 0;
bool _tim1O = 0;
unsigned long _tim1P = 0UL;
int _swi2;
float _Terminal_39824896;
bool _Terminal_149578762;
int _disp5oldLength = 0;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _changeNumber2_Out = 0;
float _changeNumber2_OLV;
bool _tim2I = 0;
bool _tim2O = 0;
unsigned long _tim2P = 0UL;
int _swi4;
int _disp7oldLength = 0;
int _disp9oldLength = 0;
bool _Terminal_247781236;
int _mux2;
int _mux1;
bool _tim6I = 0;
bool _tim6O = 0;
unsigned long _tim6P = 0UL;
int _disp4oldLength = 0;
bool _trgr1 = 0;
float _Terminal_165363456;
bool _Terminal_249445761;
int _disp10oldLength = 0;
bool _bounseInputD13S = 0;
bool _bounseInputD13O = 0;
unsigned long _bounseInputD13P = 0UL;
int _swi1;
bool _tim3I = 0;
bool _tim3O = 0;
unsigned long _tim3P = 0UL;
int _disp11oldLength = 0;
bool _count2I = 0;
int _count2_Value = 0;
bool _changeNumber1_Out = 0;
float _changeNumber1_OLV;
bool _trgr2 = 0;
int _disp6oldLength = 0;
int _disp8oldLength = 0;
bool _tim5I = 0;
bool _tim5O = 0;
unsigned long _tim5P = 0UL;
bool _Terminal_96510334;
int _disp1oldLength = 0;
int _disp2oldLength = 0;
bool _count1I = 0;
int _count1_Value = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
float _swi3;
int _disp3oldLength = 0;
float _tempVariable_float;
void setup()
{
    pinMode(13, INPUT_PULLUP);
    pinMode(8, OUTPUT);
    digitalWrite(8, 0);
    pinMode(7, OUTPUT);
    digitalWrite(7, 0);
    pinMode(18, OUTPUT);
    digitalWrite(18, 0);
    pinMode(19, OUTPUT);
    digitalWrite(19, 0);
    pinMode(6, OUTPUT);
    digitalWrite(6, 0);
    _lcd1.begin(20, 4);
    _bounseInputD13O =    digitalRead(13);
    if(!0) 
    {
        Timer1.initialize();
        	 	 // инициализировать timer1
        Timer1.setPeriod(100);
        	
    }
    if(9!=0)
    {
          Timer1.pwm(9 , 0); // задать шим сигнал на выводе pin, коэффициент заполнения 0%
    }
    if(10!=0)
    {
          Timer1.pwm(10 , 0); // задать шим сигнал на выводе pin, коэффициент заполнения 0%
    }
    if(0!=0)
    {
          Timer1.pwm(0 , 0); // задать шим сигнал на выводе pin, коэффициент заполнения 0%
    }
}
void loop()
{
    if (_isNeedClearDisp1) 
    {
        _lcd1.clear();
        _isNeedClearDisp1= 0;
    }
    bool  _bounceInputTmpD13 =  (digitalRead (13));
    if (_bounseInputD13S)
    {
        if (millis() >= (_bounseInputD13P + 40))
        {
            _bounseInputD13O= _bounceInputTmpD13;
            _bounseInputD13S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD13 != _bounseInputD13O)
        {
            _bounseInputD13S=1;
            _bounseInputD13P = millis();
        }
    }
    //Плата:1
//Наименование:Измерение параметров панели 1
    PWM_1_177117968_2 = _swi4;
    PWM_2_177117968_2 = _swi2;
    PWM_3_177117968_2 = 0;
    if(9!=0)
    {
        Timer1.setPwmDuty(9 ,  PWM_1_177117968_2);
    }
    if(10!=0)
    {
        Timer1.setPwmDuty(10 ,  PWM_2_177117968_2);
    }
    if(0!=0)
    {
        Timer1.setPwmDuty(0 ,  PWM_3_177117968_2);
    }
    digitalWrite(18, (((analogRead (0)))/(40.96)) <= (10.5));
    _Terminal_247781236 = (((analogRead (0)))/(40.96)) <= (10.5);
    _Terminal_39824896 = ((analogRead (1)))/(102.3);
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("I1=")) + ((_floatToStringWitRaz(((analogRead (1)))/(102.3),1))) + (String("A"))))).length();
        if (_disp1oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp1oldLength = _dispTempLength1;
        _lcd1.setCursor(9, 0);
        _lcd1.print((((String("I1=")) + ((_floatToStringWitRaz(((analogRead (1)))/(102.3),1))) + (String("A")))));
    }
     else 
    {
        if (_disp1oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp1oldLength = 0;
        }
    }
    if (_changeNumber2_Out) 
    {
        _changeNumber2_Out = 0;
    }
     else 
    {
        _tempVariable_float = (((analogRead (0)))/(40.96))*(((analogRead (1)))/(102.3));
        if (_tempVariable_float != _changeNumber2_OLV) 
        {
            _changeNumber2_OLV = _tempVariable_float;
            _changeNumber2_Out = 1;
        }
    }
    if (!(0))
    {
         if (_tim2I) 
        {
             if (flprog::isTimer(_tim2P, 1000)) 
            {
                _tim2O = 1;
            }
        }
         else 
        {
            _tim2I =1;
            _tim2P = millis();
        }
    }
     else 
    {
        _tim2O = 0;
        _tim2I = 0;
    }
    if(_tim2O)
    {
        _swi1=_gtv2;
    }
    else
    {
        _swi1=0;
    }
    if (((((analogRead (0)))/(40.96))*(((analogRead (1)))/(102.3))) < ((_swi1)*(1.00)))
    {
         if (_tim3I) 
        {
             if (flprog::isTimer(_tim3P, 20)) 
            {
                _tim3O = 1;
            }
        }
         else 
        {
            _tim3I =1;
            _tim3P = millis();
        }
    }
     else 
    {
        _tim3O = 0;
        _tim3I = 0;
    }
    digitalWrite(8, _tim3O);
    if (((((_changeNumber2_Out) && (((((analogRead (0)))/(40.96))*(((analogRead (1)))/(102.3))) > (_swi1)))) || (0))) 
    {
        _gtv2 = (((analogRead (0)))/(40.96))*(((analogRead (1)))/(102.3));
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("P1=")) + ((_floatToStringWitRaz((((analogRead (0)))/(40.96))*(((analogRead (1)))/(102.3)),0))) + (String("W"))))).length();
        if (_disp2oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp2oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 2);
        _lcd1.print((((String("P1=")) + ((_floatToStringWitRaz((((analogRead (0)))/(40.96))*(((analogRead (1)))/(102.3)),0))) + (String("W")))));
    }
     else 
    {
        if (_disp2oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp2oldLength = 0;
        }
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("U1=")) + ((_floatToStringWitRaz(((analogRead (0)))/(40.96),1))) + (String("V"))))).length();
        if (_disp6oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp6oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 0);
        _lcd1.print((((String("U1=")) + ((_floatToStringWitRaz(((analogRead (0)))/(40.96),1))) + (String("V")))));
    }
     else 
    {
        if (_disp6oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp6oldLength = 0;
        }
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("U=")) + ((_floatToStringWitRaz(((analogRead (3)))/(40.96),1))) + (String("V"))))).length();
        if (_disp7oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp7oldLength = _dispTempLength1;
        _lcd1.setCursor(6, 3);
        _lcd1.print((((String("U=")) + ((_floatToStringWitRaz(((analogRead (3)))/(40.96),1))) + (String("V")))));
    }
     else 
    {
        if (_disp7oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp7oldLength = 0;
        }
    }
    _Terminal_165363456 = ((analogRead (3)))/(40.96);
    digitalWrite(6, (((analogRead (3)))/(40.96)) <= (10.5));
    //Плата:2
//Наименование:ИЗМЕРЕНИЕ MPPT ПАНЕЛИ 1
    if (!(_bounseInputD13O))
    {
         if (_tim1I) 
        {
             if (flprog::isTimer(_tim1P, 300)) 
            {
                _tim1O = 1;
            }
        }
         else 
        {
            _tim1I =1;
            _tim1P = millis();
        }
    }
     else 
    {
        _tim1O = 0;
        _tim1I = 0;
    }
    if(0) _trgr1 = 0;
    if(_gtv1) _trgr1 = 1;
    if (((!(_tim3O)) && (((_tim1O) && (!(_trgr1)))))) 
    {
         if (! _gen1I) 
        {
            _gen1I = 1;
            _gen1O = 1;
            _gen1P = millis();
        }
    }
     else 
    {
        _gen1I = 0 ;
        _gen1O= 0;
    }
    if (_gen1I) 
    {
          if (flprog::isTimer (_gen1P , 30)) 
        {
             _gen1P = millis();
            _gen1O = ! _gen1O;
        }
    }
    if (((_gtv1) || (0)))
    {
        _count1_Value = 0;
    }
     else 
    {
        if (_gen1O)
        {
            if (! _count1I) 
            {
                _count1I = 1;
                if(_count1_Value < 20) 
                {
                    _count1_Value = _count1_Value + 1;
                }
            }
        }
         else 
        {
            _count1I = 0;
        }
    }
    if (!(0)) 
    {
        _dispTempLength1 = (((String(_count1_Value, DEC)))).length();
        if (_disp4oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp4oldLength = _dispTempLength1;
        _lcd1.setCursor(18, 0);
        _lcd1.print(((String(_count1_Value, DEC))));
    }
     else 
    {
        if (_disp4oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp4oldLength = 0;
        }
    }
    if((_count1_Value) == 0) 
    {
        _mux1 = 0;
    }
    if((_count1_Value) == 1) 
    {
        _mux1 = 20;
    }
    if((_count1_Value) == 2) 
    {
        _mux1 = 40;
    }
    if((_count1_Value) == 3) 
    {
        _mux1 = 60;
    }
    if((_count1_Value) == 4) 
    {
        _mux1 = 80;
    }
    if((_count1_Value) == 5) 
    {
        _mux1 = 100;
    }
    if((_count1_Value) == 6) 
    {
        _mux1 = 150;
    }
    if((_count1_Value) == 7) 
    {
        _mux1 = 200;
    }
    if((_count1_Value) == 8) 
    {
        _mux1 = 300;
    }
    if((_count1_Value) == 9) 
    {
        _mux1 = 350;
    }
    if((_count1_Value) == 10) 
    {
        _mux1 = 400;
    }
    if((_count1_Value) == 11) 
    {
        _mux1 = 450;
    }
    if((_count1_Value) == 12) 
    {
        _mux1 = 500;
    }
    if((_count1_Value) == 13) 
    {
        _mux1 = 550;
    }
    if((_count1_Value) == 14) 
    {
        _mux1 = 600;
    }
    if((_count1_Value) == 15) 
    {
        _mux1 = 650;
    }
    if((_count1_Value) == 16) 
    {
        _mux1 = 700;
    }
    if((_count1_Value) == 17) 
    {
        _mux1 = 800;
    }
    if((_count1_Value) == 18) 
    {
        _mux1 = 900;
    }
    if((_count1_Value) == 19) 
    {
        _mux1 = 950;
    }
    _Terminal_96510334 = (_Terminal_165363456) >= (14.00);
    if(((_Terminal_149578762) || ((_Terminal_165363456) >= (14.00)) || (_Terminal_247781236)))
    {
        _swi2=0;
    }
    else
    {
        _swi2=_mux1;
    }
    //Плата:3
//Наименование:Измерение параметров панели 2
    digitalWrite(19, (((analogRead (2)))/(40.96)) <= (10.5));
    _Terminal_249445761 = (((analogRead (2)))/(40.96)) <= (10.5);
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("I=")) + ((_floatToStringWitRaz((((analogRead (6)))/(102.3))+(_Terminal_39824896),1))) + (String("A"))))).length();
        if (_disp11oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp11oldLength = _dispTempLength1;
        _lcd1.setCursor(14, 3);
        _lcd1.print((((String("I=")) + ((_floatToStringWitRaz((((analogRead (6)))/(102.3))+(_Terminal_39824896),1))) + (String("A")))));
    }
     else 
    {
        if (_disp11oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp11oldLength = 0;
        }
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("I2=")) + ((_floatToStringWitRaz(((analogRead (6)))/(102.3),1))) + (String("A"))))).length();
        if (_disp5oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp5oldLength = _dispTempLength1;
        _lcd1.setCursor(9, 1);
        _lcd1.print((((String("I2=")) + ((_floatToStringWitRaz(((analogRead (6)))/(102.3),1))) + (String("A")))));
    }
     else 
    {
        if (_disp5oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp5oldLength = 0;
        }
    }
    if (_changeNumber1_Out) 
    {
        _changeNumber1_Out = 0;
    }
     else 
    {
        _tempVariable_float = (((analogRead (2)))/(40.96))*(((analogRead (6)))/(102.3));
        if (_tempVariable_float != _changeNumber1_OLV) 
        {
            _changeNumber1_OLV = _tempVariable_float;
            _changeNumber1_Out = 1;
        }
    }
    if (!(0))
    {
         if (_tim5I) 
        {
             if (flprog::isTimer(_tim5P, 1000)) 
            {
                _tim5O = 1;
            }
        }
         else 
        {
            _tim5I =1;
            _tim5P = millis();
        }
    }
     else 
    {
        _tim5O = 0;
        _tim5I = 0;
    }
    if(_tim5O)
    {
        _swi3=_gtv3;
    }
    else
    {
        _swi3=0;
    }
    if (((((analogRead (2)))/(40.96))*(((analogRead (6)))/(102.3))) < ((_swi3)*(1.00)))
    {
         if (_tim4I) 
        {
             if (flprog::isTimer(_tim4P, 20)) 
            {
                _tim4O = 1;
            }
        }
         else 
        {
            _tim4I =1;
            _tim4P = millis();
        }
    }
     else 
    {
        _tim4O = 0;
        _tim4I = 0;
    }
    digitalWrite(7, _tim4O);
    if (((((_changeNumber1_Out) && (((((analogRead (2)))/(40.96))*(((analogRead (6)))/(102.3))) > (_swi3)))) || (0))) 
    {
        _gtv3 = (((analogRead (2)))/(40.96))*(((analogRead (6)))/(102.3));
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("P2=")) + ((_floatToStringWitRaz((((analogRead (2)))/(40.96))*(((analogRead (6)))/(102.3)),0))) + (String("W"))))).length();
        if (_disp8oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp8oldLength = _dispTempLength1;
        _lcd1.setCursor(9, 2);
        _lcd1.print((((String("P2=")) + ((_floatToStringWitRaz((((analogRead (2)))/(40.96))*(((analogRead (6)))/(102.3)),0))) + (String("W")))));
    }
     else 
    {
        if (_disp8oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp8oldLength = 0;
        }
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("U2=")) + ((_floatToStringWitRaz(((analogRead (2)))/(40.96),1))) + (String("V"))))).length();
        if (_disp3oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp3oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 1);
        _lcd1.print((((String("U2=")) + ((_floatToStringWitRaz(((analogRead (2)))/(40.96),1))) + (String("V")))));
    }
     else 
    {
        if (_disp3oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp3oldLength = 0;
        }
    }
    //Плата:4
//Наименование:Измерение МРРТ панели 2
    if (!(_bounseInputD13O))
    {
         if (_tim6I) 
        {
             if (flprog::isTimer(_tim6P, 300)) 
            {
                _tim6O = 1;
            }
        }
         else 
        {
            _tim6I =1;
            _tim6P = millis();
        }
    }
     else 
    {
        _tim6O = 0;
        _tim6I = 0;
    }
    if(0) _trgr2 = 0;
    if(_gtv4) _trgr2 = 1;
    if (((!(_tim4O)) && (((_tim6O) && (!(_trgr2)))))) 
    {
         if (! _gen2I) 
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = millis();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
    if (_gen2I) 
    {
          if (flprog::isTimer (_gen2P , 30)) 
        {
             _gen2P = millis();
            _gen2O = ! _gen2O;
        }
    }
    if (((_gtv4) || (0)))
    {
        _count2_Value = 0;
    }
     else 
    {
        if (_gen2O)
        {
            if (! _count2I) 
            {
                _count2I = 1;
                if(_count2_Value < 20) 
                {
                    _count2_Value = _count2_Value + 1;
                }
            }
        }
         else 
        {
            _count2I = 0;
        }
    }
    if (!(0)) 
    {
        _dispTempLength1 = (((String(_count2_Value, DEC)))).length();
        if (_disp10oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp10oldLength = _dispTempLength1;
        _lcd1.setCursor(18, 1);
        _lcd1.print(((String(_count2_Value, DEC))));
    }
     else 
    {
        if (_disp10oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp10oldLength = 0;
        }
    }
    if((_count2_Value) == 0) 
    {
        _mux2 = 0;
    }
    if((_count2_Value) == 1) 
    {
        _mux2 = 20;
    }
    if((_count2_Value) == 2) 
    {
        _mux2 = 40;
    }
    if((_count2_Value) == 3) 
    {
        _mux2 = 60;
    }
    if((_count2_Value) == 4) 
    {
        _mux2 = 80;
    }
    if((_count2_Value) == 5) 
    {
        _mux2 = 100;
    }
    if((_count2_Value) == 6) 
    {
        _mux2 = 150;
    }
    if((_count2_Value) == 7) 
    {
        _mux2 = 200;
    }
    if((_count2_Value) == 8) 
    {
        _mux2 = 300;
    }
    if((_count2_Value) == 9) 
    {
        _mux2 = 350;
    }
    if((_count2_Value) == 10) 
    {
        _mux2 = 400;
    }
    if((_count2_Value) == 11) 
    {
        _mux2 = 450;
    }
    if((_count2_Value) == 12) 
    {
        _mux2 = 500;
    }
    if((_count2_Value) == 13) 
    {
        _mux2 = 550;
    }
    if((_count2_Value) == 14) 
    {
        _mux2 = 600;
    }
    if((_count2_Value) == 15) 
    {
        _mux2 = 650;
    }
    if((_count2_Value) == 16) 
    {
        _mux2 = 700;
    }
    if((_count2_Value) == 17) 
    {
        _mux2 = 800;
    }
    if((_count2_Value) == 18) 
    {
        _mux2 = 900;
    }
    if((_count2_Value) == 19) 
    {
        _mux2 = 950;
    }
    if(((_Terminal_96510334) || (_Terminal_149578762) || (_Terminal_249445761)))
    {
        _swi4=0;
    }
    else
    {
        _swi4=_mux2;
    }
    //Плата:5
//Наименование:Измерение температуры аккумулятора
    _Terminal_149578762 = (((analogRead (7)))/(2.048)) >= (45.00);
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("T=")) + ((_floatToStringWitRaz(((analogRead (7)))/(2.048),0))) + (String("C"))))).length();
        if (_disp9oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp9oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 3);
        _lcd1.print((((String("T=")) + ((_floatToStringWitRaz(((analogRead (7)))/(2.048),0))) + (String("C")))));
    }
     else 
    {
        if (_disp9oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp9oldLength = 0;
        }
    }
}
String  _floatToStringWitRaz(float value, int raz)
{
    return String(value,raz);
}
