#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
struct _poligonInexes
{
int minIndex;
int maxIndex;
}
;
int _Poligon_InArray_1[158] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 56, 57, 58, 60, 62, 63, 65, 67, 68, 70, 72, 74, 76, 78, 80, 83, 85, 87, 90, 92, 95, 98, 100, 103, 106, 109, 112, 115, 119, 122, 125, 129, 133, 137, 141, 145, 149, 153, 158, 162, 167, 172, 177, 182, 187, 192, 198, 204, 210, 216, 222, 228, 235, 241, 248, 255, 263, 270, 278, 286, 294, 302, 310, 319, 327, 336, 345, 354, 364, 373, 383, 393, 403, 413, 424, 434, 445, 456, 467, 478, 489, 500, 512, 523, 534, 546, 557, 569, 581, 592, 604, 615, 627, 639, 650, 661, 673, 684, 695, 706, 728, 738, 749, 759, 769, 779, 788};
int _Poligon_OutArray_1[158] = {273, 249, 232, 219, 209, 201, 194, 188, 182, 178, 173, 169, 166, 163, 160, 157, 154, 152, 149, 147, 145, 143, 141, 140, 138, 136, 135, 133, 132, 130, 129, 128, 127, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 6, 5, 4, 3, 2, 1, 0};
float _gtv1;
bool _gtv2;
bool _gtv3;
bool _swi2;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
int _disp2oldLength = 0;
bool _swi1;
unsigned long _stou1 = 0UL;
int _disp1oldLength = 0;
String _swi3;
bool _trgrt2 = 0;
bool _trgrt2I = 0;
bool _trgrt1 = 0;
bool _trgrt1I = 0;
void setup()
{
pinMode(7, OUTPUT);
digitalWrite(7, 0);
Wire.begin();
delay(10);
Serial.begin(9600, SERIAL_8N1);
_lcd1.init();
_lcd1.backlight();
_stou1 = millis();
}
void loop()
{
if (_isNeedClearDisp1)
{
_lcd1.clear();
_isNeedClearDisp1= 0;
}
//Плата:1
_gtv1 = (_poligon(((analogRead (0))), _Poligon_InArray_1, _Poligon_OutArray_1, 158));
if (!(0))
{
if (! _gen1I)
{
_gen1I = 1;
_gen1O = 1;
_gen1P = millis();
}
}
else
{
_gen1I = 0 ;
_gen1O= 0;
}
if (_gen1I && _gen1O) _gen1O = !(_isTimer(_gen1P , 2000));
_gtv2 = _gen1O;
//Плата:2
if (_gtv2 == 0)
{
if (!(_gtv2))
{
_dispTempLength1 = ((((String("temp")) + ((_floatToStringWitRaz(_gtv1,2)))))).length();
if (_disp1oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print((((String("temp")) + ((_floatToStringWitRaz(_gtv1,2))))));
}
else
{
if (_disp1oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp1oldLength = 0;
}
}
if (!(0))
{
if (_isTimer(_stou1, 1000))
{
Serial.println(((String("temp")) + ((_floatToStringWitRaz(_gtv1,2)))));
_stou1 = millis();
}
}
else
{
_stou1 = millis();
}
if ((_gtv1) > (30.00))
{
if (_trgrt2I)
{
_trgrt2 = 0;
}
else
{
_trgrt2 = 1;
_trgrt2I = 1;
}
}
else
{
_trgrt2 = 0;
_trgrt2I = 0;
}
;
if ((_gtv1) < (26.00))
{
if (_trgrt1I)
{
_trgrt1 = 0;
}
else
{
_trgrt1 = 1;
_trgrt1I = 1;
}
}
else
{
_trgrt1 = 0;
_trgrt1I = 0;
}
;
if(_trgrt1)
{
_swi1=1;
}
else
{
_swi1=_gtv3;
}
if(_trgrt2)
{
_swi2=0;
}
else
{
_swi2=_swi1;
}
if(_swi2)
{
_swi3=String("vkl");
}
else
{
_swi3=String("otkl");
}
if (!(_gtv2))
{
_dispTempLength1 = ((((String(" rele ")) + (_swi3)))).length();
if (_disp2oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp2oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print((((String(" rele ")) + (_swi3))));
}
else
{
if (_disp2oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp2oldLength = 0;
}
}
_gtv3 = _swi2;
digitalWrite(7, _gtv3);
}
}
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));
}
}
int _poligon(int value, int intArray[], int outArray[], int arraySize)
{
struct _poligonInexes indexes;
indexes = _getPoligonIndexes(value, intArray, arraySize);
return map(value, intArray[indexes.minIndex], intArray[indexes.maxIndex], outArray[indexes.minIndex], outArray[indexes.maxIndex]);
}
struct _poligonInexes _getPoligonIndexes(int value, int array[], int arraySize)
{
struct _poligonInexes result;
int i;
result.minIndex = 0;
result.maxIndex = 0;
for (i = 0; i < arraySize; i++)
{
if (array [result.minIndex] > array[i])
{
result.minIndex = i;
}
if (array [result.maxIndex] < array[i])
{
result.maxIndex = i;
}
}
for (i = 0; i < arraySize; i++)
{
if ((array [i] >= value) && (array [result.maxIndex] > array[i]))
{
result.maxIndex = i;
}
}
if (result.maxIndex==0)
{
result.minIndex = 0;
result.maxIndex=1;
}
else
{
result.minIndex = result.maxIndex -1;
}
return result;
return result;
}