#include <Wire.h>
#include "flprogUtilites.h"
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 _mcp4725_60;
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
bool _count2I = 0;
bool _count2_SCST = 0;
int _count2_Value = 0;
bool _Terminal_202749383;
bool _Terminal_11366607;
bool _gen3I = 0;
bool _gen3O = 0;
unsigned long _gen3P = 0UL;
String _swi1;
int _disp2oldLength = 0;
bool _bounseInputD2S = 0;
bool _bounseInputD2O = 0;
unsigned long _bounseInputD2P = 0UL;
bool _bounseInputD3S = 0;
bool _bounseInputD3O = 0;
unsigned long _bounseInputD3P = 0UL;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
int _disp1oldLength = 0;
int _mux2;
int _tempVariable_int;
void setup()
{
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    Wire.begin();
    delay(10);
    _mcp4725_60.begin(0x60);
    _lcd1.init();
    _lcd1.backlight();
    _bounseInputD3O =    digitalRead(3);
    _bounseInputD2O =    digitalRead(2);
}
void loop()
{
    if (_isNeedClearDisp1) 
    {
        _lcd1.clear();
        _isNeedClearDisp1= 0;
    }
    bool  _bounceInputTmpD3 =  (digitalRead (3));
    if (_bounseInputD3S)
    {
        if (millis() >= (_bounseInputD3P + 40))
        {
            _bounseInputD3O= _bounceInputTmpD3;
            _bounseInputD3S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD3 != _bounseInputD3O)
        {
            _bounseInputD3S=1;
            _bounseInputD3P = millis();
        }
    }
    bool  _bounceInputTmpD2 =  (digitalRead (2));
    if (_bounseInputD2S)
    {
        if (millis() >= (_bounseInputD2P + 40))
        {
            _bounseInputD2O= _bounceInputTmpD2;
            _bounseInputD2S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD2 != _bounseInputD2O)
        {
            _bounseInputD2S=1;
            _bounseInputD2P = millis();
        }
    }
    //Плата:1
//Наименование:ИНДИКАЦИЯ ТОКА И НАПРЯЖ.
    if(_Terminal_202749383)
    {
        _swi1=String("START");
    }
    else
    {
        _swi1=String("");
    }
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("U=")) + ((_floatToStringWitRaz(((analogRead (0)))/(6.02),1))) + (String("V  ")) + (_swi1)))).length();
        if (_disp1oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp1oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 0);
        _lcd1.print((((String("U=")) + ((_floatToStringWitRaz(((analogRead (0)))/(6.02),1))) + (String("V  ")) + (_swi1))));
    }
     else 
    {
        if (_disp1oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp1oldLength = 0;
        }
    }
    _Terminal_11366607 = ((((analogRead (1)))/(10.24))-(0.9)) <= (((analogRead (2)))/(10.24));
    if (!(0)) 
    {
        _dispTempLength1 = ((((String("I=")) + ((_floatToStringWitRaz((((analogRead (1)))/(10.24))-(0.9),1))) + (String("mA ")) + ((_floatToStringWitRaz((((analogRead (2)))/(10.24))+(10.00),0))) + (String("mA"))))).length();
        if (_disp2oldLength > _dispTempLength1) 
        {
            _isNeedClearDisp1 = 1;
        }
        _disp2oldLength = _dispTempLength1;
        _lcd1.setCursor(0, 1);
        _lcd1.print((((String("I=")) + ((_floatToStringWitRaz((((analogRead (1)))/(10.24))-(0.9),1))) + (String("mA ")) + ((_floatToStringWitRaz((((analogRead (2)))/(10.24))+(10.00),0))) + (String("mA")))));
    }
     else 
    {
        if (_disp2oldLength > 0) 
        {
            _isNeedClearDisp1 = 1;
            _disp2oldLength = 0;
        }
    }
    //Плата:2
//Наименование:УСТАНОВКА ТОКА
    if (((_Terminal_11366607) && (!(_bounseInputD2O)))) 
    {
         if (! _gen3I) 
        {
            _gen3I = 1;
            _gen3O = 1;
            _gen3P = millis();
        }
    }
     else 
    {
        _gen3I = 0 ;
        _gen3O= 0;
    }
    if (_gen3I) 
    {
          if (flprog::isTimer (_gen3P , 300)) 
        {
             _gen3P = millis();
            _gen3O = ! _gen3O;
        }
    }
    _Terminal_202749383 = ((((_Terminal_11366607) && (!(_bounseInputD2O)))) || (!(_bounseInputD3O)));
    if (!(_bounseInputD3O)) 
    {
         if (! _gen1I) 
        {
            _gen1I = 1;
            _gen1O = 1;
            _gen1P = millis();
        }
    }
     else 
    {
        _gen1I = 0 ;
        _gen1O= 0;
    }
    if (_gen1I) 
    {
          if (flprog::isTimer (_gen1P , 300)) 
        {
             _gen1P = millis();
            _gen1O = ! _gen1O;
        }
    }
    if (_gen3O)
    {
        if (! _count2I) 
        {
            _count2I = 1;
            if(_count2_Value < 21) 
            {
                _count2_Value = _count2_Value + 1;
            }
        }
    }
     else 
    {
        _count2I = 0;
    }
    if (_gen1O)
    {
        if (! _count2_SCST) 
        {
            _count2_SCST = 1;
            if(_count2_Value > 0) 
            {
                _count2_Value = _count2_Value - 1;
            }
        }
    }
     else 
    {
        _count2_SCST = 0;
    }
    if((_count2_Value) == 0) 
    {
        _mux2 = 0;
    }
    if((_count2_Value) == 1) 
    {
        _mux2 = 200;
    }
    if((_count2_Value) == 2) 
    {
        _mux2 = 400;
    }
    if((_count2_Value) == 3) 
    {
        _mux2 = 600;
    }
    if((_count2_Value) == 4) 
    {
        _mux2 = 800;
    }
    if((_count2_Value) == 5) 
    {
        _mux2 = 1200;
    }
    if((_count2_Value) == 6) 
    {
        _mux2 = 1400;
    }
    if((_count2_Value) == 7) 
    {
        _mux2 = 1600;
    }
    if((_count2_Value) == 8) 
    {
        _mux2 = 1800;
    }
    if((_count2_Value) == 9) 
    {
        _mux2 = 2000;
    }
    if((_count2_Value) == 10) 
    {
        _mux2 = 2200;
    }
    if((_count2_Value) == 11) 
    {
        _mux2 = 2400;
    }
    if((_count2_Value) == 12) 
    {
        _mux2 = 2600;
    }
    if((_count2_Value) == 13) 
    {
        _mux2 = 2800;
    }
    if((_count2_Value) == 14) 
    {
        _mux2 = 3000;
    }
    if((_count2_Value) == 15) 
    {
        _mux2 = 3200;
    }
    if((_count2_Value) == 16) 
    {
        _mux2 = 3400;
    }
    if((_count2_Value) == 17) 
    {
        _mux2 = 3600;
    }
    if((_count2_Value) == 18) 
    {
        _mux2 = 3800;
    }
    if((_count2_Value) == 19) 
    {
        _mux2 = 4000;
    }
    if((_count2_Value) == 20) 
    {
        _mux2 = 4100;
    }
    _tempVariable_int = _mux2;
    if (_tempVariable_int > 4095) 
    {
        _tempVariable_int = 4095;
    }
    if (_tempVariable_int < 0) 
    {
        _tempVariable_int = 0;
    }
    _mcp4725_60.setVoltage(_tempVariable_int, 0);
}
String  _floatToStringWitRaz(float value, int raz)
{
    return String(value,raz);
}
