bool _bounseInputD15S = 0;
bool _bounseInputD15O = 0;
unsigned long _bounseInputD15P = 0UL;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _gen4I = 0;
bool _gen4O = 0;
unsigned long _gen4P = 0UL;
bool _bounseInputD16S = 0;
bool _bounseInputD16O = 0;
unsigned long _bounseInputD16P = 0UL;
bool _bounseInputD14S = 0;
bool _bounseInputD14O = 0;
unsigned long _bounseInputD14P = 0UL;
bool _trgr8 = 0;
bool _trgr4 = 0;
bool _bounseInputD17S = 0;
bool _bounseInputD17O = 0;
unsigned long _bounseInputD17P = 0UL;
void setup()
{
    pinMode(14, INPUT_PULLUP);
    pinMode(15, INPUT_PULLUP);
    pinMode(16, INPUT_PULLUP);
    pinMode(17, INPUT_PULLUP);
    pinMode(3, OUTPUT);
    digitalWrite(3, 0);
    pinMode(2, OUTPUT);
    digitalWrite(2, 0);
    pinMode(4, OUTPUT);
    digitalWrite(4, 0);
    pinMode(6, OUTPUT);
    digitalWrite(6, 0);
    pinMode(5, OUTPUT);
    digitalWrite(5, 0);
    pinMode(7, OUTPUT);
    digitalWrite(7, 0);
    _bounseInputD16O =  digitalRead(16);
    _bounseInputD14O =  digitalRead(14);
    _bounseInputD15O =  digitalRead(15);
    _bounseInputD17O =  digitalRead(17);
}
void loop()
{
    bool  _bounceInputTmpD16 =  (digitalRead (16));
    if (_bounseInputD16S)
    {
        if (millis() >= (_bounseInputD16P + 40))
        {
            _bounseInputD16O= _bounceInputTmpD16;
            _bounseInputD16S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD16 != _bounseInputD16O)
        {
            _bounseInputD16S=1;
            _bounseInputD16P = millis();
        }
    }
    bool  _bounceInputTmpD15 =  (digitalRead (15));
    if (_bounseInputD15S)
    {
        if (millis() >= (_bounseInputD15P + 40))
        {
            _bounseInputD15O= _bounceInputTmpD15;
            _bounseInputD15S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD15 != _bounseInputD15O)
        {
            _bounseInputD15S=1;
            _bounseInputD15P = millis();
        }
    }
    bool  _bounceInputTmpD14 =  (digitalRead (14));
    if (_bounseInputD14S)
    {
        if (millis() >= (_bounseInputD14P + 40))
        {
            _bounseInputD14O= _bounceInputTmpD14;
            _bounseInputD14S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD14 != _bounseInputD14O)
        {
            _bounseInputD14S=1;
            _bounseInputD14P = millis();
        }
    }
    bool  _bounceInputTmpD17 =  (digitalRead (17));
    if (_bounseInputD17S)
    {
        if (millis() >= (_bounseInputD17P + 40))
        {
            _bounseInputD17O= _bounceInputTmpD17;
            _bounseInputD17S=0;
        }
    }
    else
    {
        if (_bounceInputTmpD17 != _bounseInputD17O)
        {
            _bounseInputD17S=1;
            _bounseInputD17P = millis();
        }
    }
    //Плата:2
    if(!(_bounseInputD17O)) _trgr8 = 0;
    if(!(_bounseInputD16O)) _trgr8 = 1;
    digitalWrite(5, _trgr8);
    digitalWrite(7, !(((!(_bounseInputD16O)) || (!(_bounseInputD17O)))));
    if (((!(_bounseInputD16O)) || (!(_bounseInputD17O)))) 
    {
         if (! _gen4I) 
        {
            _gen4I = 1;
            _gen4O = 1;
            _gen4P = micros();
        }
    }
     else 
    {
        _gen4I = 0 ;
        _gen4O= 0;
    }
    if (_gen4I) 
    {
          if (_isTimerMicros (_gen4P , (map(((analogRead (6))), (0), (1023), (1000), (20000))))) 
        {
             _gen4P = micros();
            _gen4O = ! _gen4O;
        }
    }
    digitalWrite(6, _gen4O);
    if (((!(_bounseInputD14O)) || (!(_bounseInputD15O)))) 
    {
         if (! _gen2I) 
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = micros();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
    if (_gen2I) 
    {
          if (_isTimerMicros (_gen2P , (map(((analogRead (6))), (0), (1023), (1000), (20000))))) 
        {
             _gen2P = micros();
            _gen2O = ! _gen2O;
        }
    }
    digitalWrite(3, _gen2O);
    digitalWrite(4, !(((!(_bounseInputD14O)) || (!(_bounseInputD15O)))));
    if(!(_bounseInputD15O)) _trgr4 = 0;
    if(!(_bounseInputD14O)) _trgr4 = 1;
    digitalWrite(2, _trgr4);
}
bool _isTimerMicros(unsigned long startTime, unsigned long period)
{
    unsigned long currentTime;
    currentTime = micros();
    if (currentTime>= startTime) 
    {
        return (currentTime>=(startTime + period));
    }
     else 
    {
        return (currentTime >=(4294967295-startTime+period));
    }
}
A4988
A4988