#include <Servo.h>
Servo _SM1;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _count1I = 0;
int _count1_Value = 0;
int _swi3;
int _swi1;
bool _tim1I = 0;
bool _tim1O = 0;
unsigned long _tim1P = 0UL;
int _swi2;
void setup()
{
_SM1.attach(5);
}
void loop()
{
//Плата:1
if (((analogRead (1))) >= (800))
{
if (_tim1I)
{
if (_isTimer(_tim1P, 100))
{
_tim1O = 1;
}
}
else
{
_tim1I =1;
_tim1P = millis();
}
}
else
{
_tim1O = 0;
_tim1I = 0;
}
if (_tim1O)
{
if (! _count1I)
{
_count1I = 1;
if(_count1_Value < 2)
{
_count1_Value = _count1_Value + 1;
}
}
}
else
{
_count1I = 0;
}
if(_count1_Value >= 2)
{
_count1_Value = 0;
}
if ((_count1_Value) == (0))
{
if (! _gen1I)
{
_gen1I = 1;
_gen1O = 1;
_gen1P = millis();
}
}
else
{
_gen1I = 0 ;
_gen1O= 0;
}
if (_gen1I && _gen1O) _gen1O = !(_isTimer(_gen1P , 1000));
if ((_count1_Value) == (1))
{
if (! _gen2I)
{
_gen2I = 1;
_gen2O = 1;
_gen2P = millis();
}
}
else
{
_gen2I = 0 ;
_gen2O= 0;
}
if (_gen2I && _gen2O) _gen2O = !(_isTimer(_gen2P , 1000));
if(_gen2O)
{
_swi2=160;
}
else
{
_swi2=0;
}
if (_gen2O)
{
_SM1.write (_swi2);
}
if(((!(_gen1O)) && (!(_gen2O))))
{
_swi3=80;
}
else
{
_swi3=0;
}
if (((!(_gen1O)) && (!(_gen2O))))
{
_SM1.write (_swi3);
}
if(_gen1O)
{
_swi1=5;
}
else
{
_swi1=0;
}
if (_gen1O)
{
_SM1.write (_swi1);
}
}
bool _isTimer(unsigned long startTime, unsigned long period)
{
unsigned long currentTime;
currentTime = millis();
if (currentTime>= startTime)
{
return (currentTime>=(startTime + period));
}
else
{
return (currentTime >=(4294967295-startTime+period));
}
}