Добро пожаловать,
Гость
|
Железо для умного дома
ТЕМА: Ir командер.
Ir командер. 27 Апр 2016 11:45 #12395
|
Здравствуйте! Может кому пригодится. Написал скетч под свои нужды. Умеет управлять по IR (протокол NEC) 3-мя gpio и одни шим каналом. Планирую использовать в управление люстрой и встраиваемыми светодиодными светильниками с функцией димера.
#include <IRremote.h>
IRsend _IR_Sender;
bool _IR_Sender_1_TOI_1 = 0;
bool _IR_Sender_1_TOI_2 = 0;
bool _IR_Sender_1_TOI_3 = 0;
bool _IR_Sender_1_TOI_4 = 0;
bool _IR_Sender_1_TOI_5 = 0;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _bounseInputD11S = 0;
bool _bounseInputD11O = 0;
unsigned long _bounseInputD11P = 0UL;
bool _bounseInputD9S = 0;
bool _bounseInputD9O = 0;
unsigned long _bounseInputD9P = 0UL;
bool _bounseInputD7S = 0;
bool _bounseInputD7O = 0;
unsigned long _bounseInputD7P = 0UL;
bool _bounseInputD10S = 0;
bool _bounseInputD10O = 0;
unsigned long _bounseInputD10P = 0UL;
bool _bounseInputD8S = 0;
bool _bounseInputD8O = 0;
unsigned long _bounseInputD8P = 0UL;
unsigned int Buton1[76] = {27668,9000,4350,650,500,650,500,650,500,650,500,650,500,650,500,650,500,650,500,600,1600,650,1550,650,1550,650,1550,
650,1600,650,1550,650,1550,650,1550,650,500,650,1550,650,1600,650,500,650,1550,650,500,650,500,650,500,600,1600,650,
500,650,500,600,1600,650,500,650,1550,650,1550,650,1550,650,29514,9000,2150,600,29514,9000,2150,600};
unsigned int Buton2[76] = {9542,9000,4350,650,500,650,500,650,500,650,500,650,500,600,550,600,550,600,550,600,1600,600,1600,650,1550,650,1600,
600,1600,600,1600,650,1550,650,1600,600,1600,600,550,600,550,600,1600,600,1600,650,500,650,500,600,550,600,550,600,
1600,600,1600,650,500,650,500,600,1600,650,1550,650,1550,650,29514,9000,2150,600,29514,9000,2150,600};
unsigned int Buton3[76] = {14938,9000,4400,650,500,650,500,600,550,600,550,600,500,650,500,650,500,650,500,650,1550,650,1600,600,1550,650,1600,
650,1550,650,1550,650,1600,600,1600,650,500,650,500,600,1600,650,1550,650,500,650,500,650,500,650,500,650,1550,650,
1550,650,500,650,500,650,1550,650,1600,600,1600,650,1550,650,29514,9000,2150,600,29514,9000,2150,600};
unsigned int Buton4[76] = {16044,9000,4350,650,550,600,500,650,500,650,500,650,500,650,500,650,500,600,550,600,1600,650,1550,650,1550,650,1550,
650,1600,650,1550,650,1550,650,1600,600,550,600,550,600,500,650,1600,600,1600,600,550,600,550,600,550,600,1600,600,
1600,650,1550,650,500,650,500,650,1550,650,1550,650,1600,600,29514,9000,2150,600,29514,9000,2150,600};
unsigned int Buton5[76] = {17250,9000,4400,650,500,650,500,650,500,650,500,600,550,600,550,600,550,600,500,650,1600,600,1600,600,1600,650,1550,
650,1600,600,1600,600,1600,650,1550,650,500,650,1600,600,1600,600,1600,650,1550,650,500,650,1550,650,500,650,1600,
600,500,650,500,650,500,650,500,650,1550,650,500,650,1550,650,29514,9000,2150,600,29514,9000,2150,600};
void setup()
{
pinMode(7, INPUT);
digitalWrite(7, HIGH);
pinMode(8, INPUT);
digitalWrite(8, HIGH);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
pinMode(10, INPUT);
digitalWrite(10, HIGH);
pinMode(11, INPUT);
digitalWrite(11, HIGH);
_bounseInputD11O = digitalRead(11);
_bounseInputD9O = digitalRead(9);
_bounseInputD7O = digitalRead(7);
_bounseInputD10O = digitalRead(10);
_bounseInputD8O = digitalRead(8);
}
void loop()
{
bool _bounceInputTmpD11 = (digitalRead (11));
if (_bounseInputD11S)
{
if (millis() >= (_bounseInputD11P + 40))
{_bounseInputD11O= _bounceInputTmpD11; _bounseInputD11S=0;}
}
else
{
if (_bounceInputTmpD11 != _bounseInputD11O )
{_bounseInputD11S=1; _bounseInputD11P = millis();}
}
bool _bounceInputTmpD9 = (digitalRead (9));
if (_bounseInputD9S)
{
if (millis() >= (_bounseInputD9P + 40))
{_bounseInputD9O= _bounceInputTmpD9; _bounseInputD9S=0;}
}
else
{
if (_bounceInputTmpD9 != _bounseInputD9O )
{_bounseInputD9S=1; _bounseInputD9P = millis();}
}
bool _bounceInputTmpD7 = (digitalRead (7));
if (_bounseInputD7S)
{
if (millis() >= (_bounseInputD7P + 40))
{_bounseInputD7O= _bounceInputTmpD7; _bounseInputD7S=0;}
}
else
{
if (_bounceInputTmpD7 != _bounseInputD7O )
{_bounseInputD7S=1; _bounseInputD7P = millis();}
}
bool _bounceInputTmpD10 = (digitalRead (10));
if (_bounseInputD10S)
{
if (millis() >= (_bounseInputD10P + 40))
{_bounseInputD10O= _bounceInputTmpD10; _bounseInputD10S=0;}
}
else
{
if (_bounceInputTmpD10 != _bounseInputD10O )
{_bounseInputD10S=1; _bounseInputD10P = millis();}
}
bool _bounceInputTmpD8 = (digitalRead (8));
if (_bounseInputD8S)
{
if (millis() >= (_bounseInputD8P + 40))
{_bounseInputD8O= _bounceInputTmpD8; _bounseInputD8S=0;}
}
else
{
if (_bounceInputTmpD8 != _bounseInputD8O )
{_bounseInputD8S=1; _bounseInputD8P = millis();}
}
if (!(_bounseInputD7O)) { if (! _gen1I) { _gen1I = 1; _gen1O = 1; _gen1P = millis(); } } else { _gen1I = 0 ; _gen1O= 0;}
if (_gen1I) { if ( _isTimer ( _gen1P , 10 )) { _gen1P = millis(); _gen1O = ! _gen1O;}}
if (!(_bounseInputD8O)) { if (! _gen2I) { _gen2I = 1; _gen2O = 1; _gen2P = millis(); } } else { _gen2I = 0 ; _gen2O= 0;}
if (_gen2I) { if ( _isTimer ( _gen2P , 10 )) { _gen2P = millis(); _gen2O = ! _gen2O;}}
if (_gen1O) {if (!(_
IR_Sender_1_TOI_1)) {_IR_Sender.sendRaw(Buton1,76,38);}
_IR_Sender_1_TOI_1 = 1;} else {_IR_Sender_1_TOI_1 =0;}
if (_gen2O) {if (!(_IR_Sender_1_TOI_2)) {_IR_Sender.sendRaw(Buton2,76,38);}
_IR_Sender_1_TOI_2 = 1;} else {_IR_Sender_1_TOI_2 =0;}
if (!(_bounseInputD9O)) {if (!(_IR_Sender_1_TOI_3)) {_IR_Sender.sendRaw(Buton3,76,38);}
_IR_Sender_1_TOI_3 = 1;} else {_IR_Sender_1_TOI_3 =0;}
if (!(_bounseInputD10O)) {if (!(_IR_Sender_1_TOI_4)) {_IR_Sender.sendRaw(Buton4,76,38);}
_IR_Sender_1_TOI_4 = 1;} else {_IR_Sender_1_TOI_4 =0;}
if (!(_bounseInputD11O)) {if (!(_IR_Sender_1_TOI_5)) {_IR_Sender.sendRaw(Buton5,76,38);}
_IR_Sender_1_TOI_5 = 1;} else {_IR_Sender_1_TOI_5 =0;}
}
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));}
} |
Последнее редактирование: 27 Апр 2016 11:46 от dorisca11.
Администратор запретил публиковать записи гостям.
|
Модераторы: FlyRouter
Время создания страницы: 0.136 секунд