bool _EN_Work;
byte Out_165_reg[ 1 ];
byte Out_1_165;
bool _ByteToBit_1_outArray[8];
bool _trgrt2 = 0;
bool _trgrt2I = 0;
bool _trgt1 = 0;
bool _trgt1I = 0;
bool _trgt6 = 0;
bool _trgt6I = 0;
bool _trgrt4 = 0;
bool _trgrt4I = 0;
bool _trgrt3 = 0;
bool _trgrt3I = 0;
bool _trgt2 = 0;
bool _trgt2I = 0;
bool _trgt4 = 0;
bool _trgt4I = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _trgt7 = 0;
bool _trgt7I = 0;
bool _trgrt5 = 0;
bool _trgrt5I = 0;
bool _trgrt9 = 0;
bool _trgrt9I = 0;
bool _trgt8 = 0;
bool _trgt8I = 0;
bool _trgt5 = 0;
bool _trgt5I = 0;
bool _trgrt7 = 0;
bool _trgrt7I = 0;
bool _trgrt8 = 0;
bool _trgrt8I = 0;
bool _trgrt1 = 0;
bool _trgrt1I = 0;
byte _tempVariable_byte;
void setup()
{
pinMode(2, OUTPUT);
digitalWrite(2, 0);
pinMode(3, OUTPUT);
digitalWrite(3, 0);
pinMode(4, OUTPUT);
digitalWrite(4, 0);
pinMode(5, OUTPUT);
digitalWrite(5, 0);
pinMode(6, OUTPUT);
digitalWrite(6, 0);
pinMode(7, OUTPUT);
digitalWrite(7, 0);
pinMode(8, OUTPUT);
digitalWrite(8, 0);
pinMode(8,OUTPUT);
pinMode(13,OUTPUT);
pinMode(12,INPUT);
digitalWrite(12, HIGH); //подключаем подтягивающий резистор
}
void loop()
{
//Плата:1
if (1)
{
if (! _gen2I)
{
_gen2I = 1;
_gen2O = 1;
_gen2P = millis();
}
}
else
{
_gen2I = 0 ;
_gen2O= 0;
}
if (_gen2I)
{
if (_isTimer (_gen2P , 50))
{
_gen2P = millis();
_gen2O = ! _gen2O;
}
}
if (_gen2O)
{
if (_trgrt7I)
{
_trgrt7 = 0;
}
else
{
_trgrt7 = 1;
_trgrt7I = 1;
}
}
else
{
_trgrt7 = 0;
_trgrt7I = 0;
}
;
_EN_Work = _trgrt7;
if(_EN_Work)
{
digitalWrite(8 , LOW); // Готовми данные
delayMicroseconds(2); // Пауза
digitalWrite(8 , HIGH); // Защёлкиваем данные
for (byte i = 0; i < 1 ; i++)
{
Out_165_reg[i] = read_input_165_reg() ;
}
// Читаем 165 регистры
digitalWrite(13 , LOW);
digitalWrite(8 , LOW);
delayMicroseconds(2);
digitalWrite(8 , HIGH); // Защёлкиваем данные
}
//Плата:2
Out_1_165 = Out_165_reg[0];
_tempVariable_byte = Out_1_165;
for (int i=0; i < 8; i++)
{
_ByteToBit_1_outArray[i] = bitRead(_tempVariable_byte, i);
}
if (_ByteToBit_1_outArray[6])
{
if (_trgrt1I)
{
_trgrt1 = 0;
}
else
{
_trgrt1 = 1;
_trgrt1I = 1;
}
}
else
{
_trgrt1 = 0;
_trgrt1I = 0;
}
;
bool _tmp2 = _trgrt1;
if (_tmp2)
{
if (! _trgt2I) _trgt2 = ! _trgt2;
}
_trgt2I = _tmp2;
digitalWrite(8, _trgt2);
if (_ByteToBit_1_outArray[5])
{
if (_trgrt9I)
{
_trgrt9 = 0;
}
else
{
_trgrt9 = 1;
_trgrt9I = 1;
}
}
else
{
_trgrt9 = 0;
_trgrt9I = 0;
}
;
bool _tmp1 = _trgrt9;
if (_tmp1)
{
if (! _trgt1I) _trgt1 = ! _trgt1;
}
_trgt1I = _tmp1;
digitalWrite(7, _trgt1);
if (_ByteToBit_1_outArray[4])
{
if (_trgrt3I)
{
_trgrt3 = 0;
}
else
{
_trgrt3 = 1;
_trgrt3I = 1;
}
}
else
{
_trgrt3 = 0;
_trgrt3I = 0;
}
;
bool _tmp8 = _trgrt3;
if (_tmp8)
{
if (! _trgt8I) _trgt8 = ! _trgt8;
}
_trgt8I = _tmp8;
digitalWrite(6, _trgt8);
if (_ByteToBit_1_outArray[3])
{
if (_trgrt2I)
{
_trgrt2 = 0;
}
else
{
_trgrt2 = 1;
_trgrt2I = 1;
}
}
else
{
_trgrt2 = 0;
_trgrt2I = 0;
}
;
bool _tmp7 = _trgrt2;
if (_tmp7)
{
if (! _trgt7I) _trgt7 = ! _trgt7;
}
_trgt7I = _tmp7;
digitalWrite(5, _trgt7);
if (_ByteToBit_1_outArray[2])
{
if (_trgrt8I)
{
_trgrt8 = 0;
}
else
{
_trgrt8 = 1;
_trgrt8I = 1;
}
}
else
{
_trgrt8 = 0;
_trgrt8I = 0;
}
;
bool _tmp6 = _trgrt8;
if (_tmp6)
{
if (! _trgt6I) _trgt6 = ! _trgt6;
}
_trgt6I = _tmp6;
digitalWrite(4, _trgt6);
if (_ByteToBit_1_outArray[1])
{
if (_trgrt5I)
{
_trgrt5 = 0;
}
else
{
_trgrt5 = 1;
_trgrt5I = 1;
}
}
else
{
_trgrt5 = 0;
_trgrt5I = 0;
}
;
bool _tmp5 = _trgrt5;
if (_tmp5)
{
if (! _trgt5I) _trgt5 = ! _trgt5;
}
_trgt5I = _tmp5;
digitalWrite(3, _trgt5);
if (_ByteToBit_1_outArray[0])
{
if (_trgrt4I)
{
_trgrt4 = 0;
}
else
{
_trgrt4 = 1;
_trgrt4I = 1;
}
}
else
{
_trgrt4 = 0;
_trgrt4I = 0;
}
;
bool _tmp4 = _trgrt4;
if (_tmp4)
{
if (! _trgt4I) _trgt4 = ! _trgt4;
}
_trgt4I = _tmp4;
digitalWrite(2, _trgt4);
}
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));
}
}
byte read_input_165_reg()
{
byte bytesVal = 0;
for(int i = 7; i >= 0; i--)
{
digitalWrite(13 , LOW);
bytesVal |= (digitalRead(12) ? (1<<i) : 0);
digitalWrite(13 , HIGH);
delayMicroseconds(2);
}
return(bytesVal);
}