#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
int _gtv1 = 0;
bool _tim2I = 0;
bool _tim2O = 0;
unsigned long _tim2P = 0UL;
bool _mux2;
bool _tim1I = 0;
bool _tim1O = 0;
unsigned long _tim1P = 0UL;
bool _bounseInputD5S = 0;
bool _bounseInputD5O = 0;
unsigned long _bounseInputD5P = 0UL;
bool _bounseInputD7S = 0;
bool _bounseInputD7O = 0;
unsigned long _bounseInputD7P = 0UL;
bool _bounseInputD4S = 0;
bool _bounseInputD4O = 0;
unsigned long _bounseInputD4P = 0UL;
bool _bounseInputD3S = 0;
bool _bounseInputD3O = 0;
unsigned long _bounseInputD3P = 0UL;
int _swi1;
bool _mux1;
bool _bounseInputD6S = 0;
bool _bounseInputD6O = 0;
unsigned long _bounseInputD6P = 0UL;
int _swi3;
int _disp1oldLength = 0;
int _swi2;
bool _bounseInputD2S = 0;
bool _bounseInputD2O = 0;
unsigned long _bounseInputD2P = 0UL;
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, OUTPUT);
digitalWrite(8, 0);
pinMode(9, OUTPUT);
digitalWrite(9, 0);
Wire.begin();
delay(10);
_lcd1.init();
_lcd1.backlight();
_bounseInputD6O = digitalRead(6);
_bounseInputD2O = digitalRead(2);
_bounseInputD7O = digitalRead(7);
_bounseInputD3O = digitalRead(3);
_bounseInputD5O = digitalRead(5);
_bounseInputD4O = digitalRead(4);
}
void loop()
{
if (_isNeedClearDisp1)
{
_lcd1.clear();
_isNeedClearDisp1= 0;
}
bool _bounceInputTmpD4 = (digitalRead (4));
if (_bounseInputD4S)
{
if (millis() >= (_bounseInputD4P + 40))
{
_bounseInputD4O= _bounceInputTmpD4;
_bounseInputD4S=0;
}
}
else
{
if (_bounceInputTmpD4 != _bounseInputD4O)
{
_bounseInputD4S=1;
_bounseInputD4P = millis();
}
}
bool _bounceInputTmpD5 = (digitalRead (5));
if (_bounseInputD5S)
{
if (millis() >= (_bounseInputD5P + 40))
{
_bounseInputD5O= _bounceInputTmpD5;
_bounseInputD5S=0;
}
}
else
{
if (_bounceInputTmpD5 != _bounseInputD5O)
{
_bounseInputD5S=1;
_bounseInputD5P = 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 _bounceInputTmpD7 = (digitalRead (7));
if (_bounseInputD7S)
{
if (millis() >= (_bounseInputD7P + 40))
{
_bounseInputD7O= _bounceInputTmpD7;
_bounseInputD7S=0;
}
}
else
{
if (_bounceInputTmpD7 != _bounseInputD7O)
{
_bounseInputD7S=1;
_bounseInputD7P = 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 ((_gtv1) == (0))
{
if (_tim2I)
{
if (_isTimer(_tim2P, 1000))
{
_tim2O = 1;
}
}
else
{
_tim2I =1;
_tim2P = millis();
}
}
else
{
_tim2O = 0;
_tim2I = 0;
}
if ((_gtv1) != (0))
{
if (_tim1I)
{
if (_isTimer(_tim1P, 1000))
{
_tim1O = 1;
}
}
else
{
_tim1I =1;
_tim1P = millis();
}
}
else
{
_tim1O = 0;
_tim1I = 0;
}
if(((_tim2O) && (((!(_bounseInputD2O)) || (_bounseInputD4O)))))
{
_swi1=1;
}
else
{
_swi1=_gtv1;
}
if(((_tim2O) && (((!(_bounseInputD3O)) || (_bounseInputD5O)))))
{
_swi2=2;
}
else
{
_swi2=_swi1;
}
if((((((_gtv1) == (1)) && (!(_bounseInputD6O)))) || ((((_gtv1) == (2)) && (!(_bounseInputD7O)))) || (((_tim1O) && (((((!(_bounseInputD2O)) || (_bounseInputD4O))) || (((!(_bounseInputD3O)) || (_bounseInputD5O)))))))))
{
_swi3=0;
}
else
{
_swi3=_swi2;
}
if (!(0))
{
_dispTempLength1 = (((String(_swi3, DEC)))).length();
if (_disp1oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print(((String(_swi3, DEC))));
}
else
{
if (_disp1oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp1oldLength = 0;
}
}
_gtv1 = _swi3;
//Плата:2
//Наименование:Управление мотором
if((_gtv1) == 0)
{
_mux1 = 0;
}
if((_gtv1) == 1)
{
_mux1 = 1;
}
if((_gtv1) == 2)
{
_mux1 = 0;
}
digitalWrite(8, _mux1);
if((_gtv1) == 0)
{
_mux2 = 0;
}
if((_gtv1) == 1)
{
_mux2 = 0;
}
if((_gtv1) == 2)
{
_mux2 = 1;
}
digitalWrite(9, _mux2);
}
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));
}
}