#include <Wire.h>
#include "flprogUtilites.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C _lcd1(0x027, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
int _disp1oldLength = 0;
int _disp3oldLength = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _bounseInputD18S = 0;
bool _bounseInputD18O = 0;
unsigned long _bounseInputD18P = 0UL;
bool _bounseInputD19S = 0;
bool _bounseInputD19O = 0;
unsigned long _bounseInputD19P = 0UL;
bool _trgr2 = 0;
bool _D1B1 = 0;
int _disp2oldLength = 0;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _D1B2 = 0;
bool _trgr6 = 0;
bool _trgr3 = 0;
int _disp7oldLength = 0;
bool _trgr1 = 0;
bool _trgr4 = 0;
bool _trgr7 = 0;
bool _D1B3 = 0;
bool _bounseInputD5S = 0;
bool _bounseInputD5O = 0;
unsigned long _bounseInputD5P = 0UL;
bool _trgr5 = 0;
int _disp4oldLength = 0;
int _disp5oldLength = 0;
bool _gen3I = 0;
bool _gen3O = 0;
unsigned long _gen3P = 0UL;
int _disp6oldLength = 0;
bool _D1B4 = 0;
void setup()
{
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(18, INPUT);
pinMode(19, INPUT);
pinMode(12, OUTPUT);
digitalWrite(12, 0);
pinMode(14, OUTPUT);
digitalWrite(14, 0);
Wire.begin();
delay(10);
_lcd1.init();
_lcd1.noBacklight();
_bounseInputD5O = digitalRead(5);
_bounseInputD18O = digitalRead(18);
_bounseInputD19O = digitalRead(19);
}
void loop()
{
if (_isNeedClearDisp1)
{
_lcd1.clear();
_isNeedClearDisp1= 0;
}
bool _bounceInputTmpD18 = (digitalRead (18));
if (_bounseInputD18S)
{
if (millis() >= (_bounseInputD18P + 40))
{
_bounseInputD18O= _bounceInputTmpD18;
_bounseInputD18S=0;
}
}
else
{
if (_bounceInputTmpD18 != _bounseInputD18O)
{
_bounseInputD18S=1;
_bounseInputD18P = millis();
}
}
bool _bounceInputTmpD5 = (digitalRead (5));
if (_bounseInputD5S)
{
if (millis() >= (_bounseInputD5P + 40))
{
_bounseInputD5O= _bounceInputTmpD5;
_bounseInputD5S=0;
}
}
else
{
if (_bounceInputTmpD5 != _bounseInputD5O)
{
_bounseInputD5S=1;
_bounseInputD5P = millis();
}
}
bool _bounceInputTmpD19 = (digitalRead (19));
if (_bounseInputD19S)
{
if (millis() >= (_bounseInputD19P + 40))
{
_bounseInputD19O= _bounceInputTmpD19;
_bounseInputD19S=0;
}
}
else
{
if (_bounceInputTmpD19 != _bounseInputD19O)
{
_bounseInputD19S=1;
_bounseInputD19P = millis();
}
}
//Board:1
if(_bounseInputD19O) _trgr3 = 0;
if(_bounseInputD18O) _trgr3 = 1;
if(_bounseInputD19O) _trgr2 = 0;
if(_bounseInputD5O) _trgr2 = 1;
if(_bounseInputD19O) _trgr1 = 0;
if((digitalRead (4))) _trgr1 = 1;
if(_bounseInputD19O) _trgr6 = 0;
if(((_trgr3) && (!(_trgr1)) && (!(_trgr2)))) _trgr6 = 1;
if (_trgr6)
{
if (! _gen3I)
{
_gen3I = 1;
_gen3O = 1;
_gen3P = millis();
}
}
else
{
_gen3I = 0 ;
_gen3O= 0;
}
if (_gen3I)
{
if (flprog::isTimer (_gen3P , 1000))
{
_gen3P = millis();
_gen3O = ! _gen3O;
}
}
if(_gen3O)
{
if(! _D1B3)
{
_lcd1.backlight();
_D1B3=1;
}
}
else
{
if(_D1B3)
{
_lcd1.noBacklight();
_D1B3=0;
}
}
if (_trgr6)
{
_dispTempLength1 = (String("Janela")).length();
if (_disp7oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp7oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print(String("Janela"));
}
else
{
if (_disp7oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp7oldLength = 0;
}
}
if (_trgr6)
{
_dispTempLength1 = (String("S3 Acionado")).length();
if (_disp3oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp3oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print(String("S3 Acionado"));
}
else
{
if (_disp3oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp3oldLength = 0;
}
}
if(_bounseInputD19O) _trgr5 = 0;
if(((_trgr2) && (!(_trgr1)) && (!(_trgr3)))) _trgr5 = 1;
if (_trgr5)
{
if (! _gen2I)
{
_gen2I = 1;
_gen2O = 1;
_gen2P = millis();
}
}
else
{
_gen2I = 0 ;
_gen2O= 0;
}
if (_gen2I)
{
if (flprog::isTimer (_gen2P , 500))
{
_gen2P = millis();
_gen2O = ! _gen2O;
}
}
if(_gen2O)
{
if(! _D1B2)
{
_lcd1.backlight();
_D1B2=1;
}
}
else
{
if(_D1B2)
{
_lcd1.noBacklight();
_D1B2=0;
}
}
if (_trgr5)
{
_dispTempLength1 = (String("Porta Fundos")).length();
if (_disp6oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp6oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print(String("Porta Fundos"));
}
else
{
if (_disp6oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp6oldLength = 0;
}
}
if (_trgr5)
{
_dispTempLength1 = (String("S2 Acionado")).length();
if (_disp2oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp2oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print(String("S2 Acionado"));
}
else
{
if (_disp2oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp2oldLength = 0;
}
}
if(_bounseInputD19O) _trgr4 = 0;
if(((_trgr1) && (!(_trgr2)) && (!(_trgr3)))) _trgr4 = 1;
if (_trgr4)
{
if (! _gen1I)
{
_gen1I = 1;
_gen1O = 1;
_gen1P = millis();
}
}
else
{
_gen1I = 0 ;
_gen1O= 0;
}
if (_gen1I)
{
if (flprog::isTimer (_gen1P , 500))
{
_gen1P = millis();
_gen1O = ! _gen1O;
}
}
if(_gen1O)
{
if(! _D1B1)
{
_lcd1.backlight();
_D1B1=1;
}
}
else
{
if(_D1B1)
{
_lcd1.noBacklight();
_D1B1=0;
}
}
if (_trgr4)
{
_dispTempLength1 = (String("Porta frente")).length();
if (_disp5oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp5oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print(String("Porta frente"));
}
else
{
if (_disp5oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp5oldLength = 0;
}
}
if (_trgr4)
{
_dispTempLength1 = (String("S1 Acionado")).length();
if (_disp1oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print(String("S1 Acionado"));
}
else
{
if (_disp1oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp1oldLength = 0;
}
}
if(!(((_trgr1) || (_trgr2) || (_trgr3))))
{
if(! _D1B4)
{
_lcd1.backlight();
_D1B4=1;
}
}
else
{
if(_D1B4)
{
_lcd1.noBacklight();
_D1B4=0;
}
}
if(_bounseInputD19O) _trgr7 = 0;
if(((_trgr1) || (_trgr2) || (_trgr3))) _trgr7 = 1;
digitalWrite(14, _trgr7);
if (!(((_trgr1) || (_trgr2) || (_trgr3))))
{
_dispTempLength1 = (String("Sistema OK")).length();
if (_disp4oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp4oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print(String("Sistema OK"));
}
else
{
if (_disp4oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp4oldLength = 0;
}
}
digitalWrite(12, ((_trgr1) || (_trgr2) || (_trgr3)));
}