#include <Wire.h>
#include <SHT2x.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT_NEW.h"
DHT _dht2;
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
float Temp_133010113_1;
float Hum_133010113_1;
int _PWDC = 0;
float _gtv1 = 2;
float _gtv2 = 4;
int _disp2oldLength = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
int _disp6oldLength = 0;
bool _trgrt1 = 0;
bool _trgrt1I = 0;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
int _disp1oldLength = 0;
bool _trgt1 = 0;
bool _trgt1I = 0;
int _disp4oldLength = 0;
bool _tim3I = 0;
bool _tim3O = 0;
unsigned long _tim3P = 0UL;
bool _gen4I = 0;
bool _gen4O = 0;
unsigned long _gen4P = 0UL;
bool _tim2I = 0;
bool _tim2O = 0;
unsigned long _tim2P = 0UL;
bool _trgr3 = 0;
bool _trgr1 = 0;
bool _bounseInputD6S = 0;
bool _bounseInputD6O = 0;
unsigned long _bounseInputD6P = 0UL;
bool _gen3I = 0;
bool _gen3O = 0;
unsigned long _gen3P = 0UL;
unsigned long _dht2LRT = 0UL;
unsigned long _dht2Tti = 0UL;
void setup()
{
pinMode(6, INPUT_PULLUP);
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(7, OUTPUT);
digitalWrite(7, 0);
pinMode(11, OUTPUT);
digitalWrite(11, 0);
pinMode(12, OUTPUT);
digitalWrite(12, 0);
Wire.begin();
delay(10);
TCCR2A = 0x00;
TCCR2B = 0x07;
TIMSK2=0x01;
TCNT2=100;
_lcd1.init();
_lcd1.backlight();
_bounseInputD6O = digitalRead(6);
_dht2.setup(10);
_dht2LRT = millis();
_dht2Tti = millis();
Wire.begin();
}
void loop()
{
if (_isNeedClearDisp1) {_lcd1.clear(); _isNeedClearDisp1= 0;}
_PWDC = 0;
bool _bounceInputTmpD6 = (digitalRead (6));
if (_bounseInputD6S)
{
if (millis() >= (_bounseInputD6P + 40))
{_bounseInputD6O= _bounceInputTmpD6; _bounseInputD6S=0;}
}
else
{
if (_bounceInputTmpD6 != _bounseInputD6O )
{_bounseInputD6S=1; _bounseInputD6P = millis();}
}
//Плата:1
Temp_133010113_1 = SHT2x.readT();
Hum_133010113_1 = SHT2x.readRH();
delay( 1000 );
if ((Temp_133010113_1) > (_gtv2)) { if (_trgrt1I) { _trgrt1 = 0;} else {_trgrt1 = 1; _trgrt1I = 1;} } else {_trgrt1 = 0; _trgrt1I = 0;};
if (1) {if (! _gen2I) { _gen2I = 1; _gen2O = 1; _gen2P = millis(); } } else { _gen2I = 0 ; _gen2O= 0; } if (_gen2I ) { if (_gen2O) { if ( _isTimer( _gen2P , 1000 )) { _gen2P = millis(); _gen2O = 0; } } else { if ( _isTimer( _gen2P , 10800000 )) { _gen2P = millis(); _gen2O = 1; } } }
if(_isTimer(_dht2Tti, 10000)) {
if(_isTimer(_dht2LRT,( _dht2.getMinimumSamplingPeriod()))) {
_dht2.readSensor();
_dht2LRT = millis();
_dht2Tti = millis();
}
}
bool _tmp1 = _bounseInputD6O;
if (_tmp1) { if (! _trgt1I) _trgt1 = ! _trgt1; }
_trgt1I = _tmp1;
if (_trgt1) { if (! _gen4I) { _gen4I = 1; _gen4O = 1; _gen4P = millis(); } } else { _gen4I = 0 ; _gen4O= 0;}
if (_gen4I) { if ( _isTimer ( _gen4P , 5000 )) { _gen4P = millis(); _gen4O = ! _gen4O;}}
if (!(_gen4O)) {
_dispTempLength1 = ((((String("Hu ")) + (( _floatToStringWitRaz((_dht2.humidity)-(27.00),2))) + (String(" %"))))).length();
if (_disp4oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp4oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print((((String("Hu ")) + (( _floatToStringWitRaz((_dht2.humidity)-(27.00),2))) + (String(" %")))));
} else {
if (_disp4oldLength > 0) {_isNeedClearDisp1 = 1; _disp4oldLength = 0;}
}
if (_gen4O) {
_dispTempLength1 = ((((String("Hp ")) + (( _floatToStringWitRaz((Hum_133010113_1)-(4.,2))) + (String(" %"))))).length();
if (_disp1oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print((((String("Hp ")) + (( _floatToStringWitRaz((Hum_133010113_1)-(4.,2))) + (String(" %")))));
} else {
if (_disp1oldLength > 0) {_isNeedClearDisp1 = 1; _disp1oldLength = 0;}
}
if (_gen4O) {
_dispTempLength1 = ((((String("Tp ")) + (( _floatToStringWitRaz(Temp_133010113_1,2))) + (String(" C"))))).length();
if (_disp6oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp6oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print((((String("Tp ")) + (( _floatToStringWitRaz(Temp_133010113_1,2))) + (String(" C")))));
} else {
if (_disp6oldLength > 0) {_isNeedClearDisp1 = 1; _disp6oldLength = 0;}
}
if (!(_gen4O)) {
_dispTempLength1 = ((((String("Tu ")) + (( _floatToStringWitRaz(_dht2.temperature,2))) + (String(" C"))))).length();
if (_disp2oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp2oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print((((String("Tu ")) + (( _floatToStringWitRaz(_dht2.temperature,2))) + (String(" C")))));
} else {
if (_disp2oldLength > 0) {_isNeedClearDisp1 = 1; _disp2oldLength = 0;}
}
if ((_dht2.temperature) >= (20.00)) { if (! _gen3I) { _gen3I = 1; _gen3O = 1; _gen3P = millis(); } } else { _gen3I = 0 ; _gen3O= 0;}
if (_gen3I) { if ( _isTimer ( _gen3P , 500 )) { _gen3P = millis(); _gen3O = ! _gen3O;}}
if((Temp_133010113_1) >= (_gtv2)) _trgr1 = 0;
if((Temp_133010113_1) <= (_gtv1)) _trgr1 = 1;
digitalWrite(5, _trgr1);
if((Temp_133010113_1) >= (_gtv2)) _trgr3 = 0;
if((Temp_133010113_1) <= (_gtv1)) _trgr3 = 1;
digitalWrite(11, !(_trgr3));
digitalWrite(2, (Temp_133010113_1) <= (_gtv1));
digitalWrite(3, !(( ((Temp_133010113_1) <= (_gtv1)) ^ ((Temp_133010113_1) >= (_gtv2)) )));
digitalWrite(4, ( ((Temp_133010113_1) >= (_gtv2)) ^ (_gen3O) ));
if ((_dht2.temperature) >= (20.00)) {if (! _gen1I) { _gen1I = 1; _gen1O = 1; _gen1P = millis(); } } else { _gen1I = 0 ; _gen1O= 0; } if (_gen1I ) { if (_gen1O) { if ( _isTimer( _gen1P , 1000 )) { _gen1P = millis(); _gen1O = 0; } } else { if ( _isTimer( _gen1P , 1500000 )) { _gen1P = millis(); _gen1O = 1; } } }
if(( (_trgrt1) || (_gen2O) || (_gen1O) )) {_tim2O = 1; _tim2I = 1;} else { if(_tim2I) {_tim2I = 0; _tim2P = millis();} else { if (_tim2O) {if ( _isTimer(_tim2P, 1200000)) _tim2O = 0;}}}
digitalWrite(7, _tim2O);
if(( (_trgrt1) || (_gen2O) || (_gen1O) )) {_tim3O = 1; _tim3I = 1;} else { if(_tim3I) {_tim3I = 0; _tim3P = millis();} else { if (_tim3O) {if ( _isTimer(_tim3P, 1200000)) _tim3O = 0;}}}
digitalWrite(12, !(_tim3O));
}
String _floatToStringWitRaz(float value, int raz)
{
return String(value,raz);
}
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));}
}
ISR(TIMER2_OVF_vect)
{ TCNT2=100;
if(_PWDC >= 1000){asm volatile ("jmp 0x0000");}else{_PWDC = _PWDC+1;};
}