/
IrRemoteLight.ino
68 lines (61 loc) · 1.76 KB
/
IrRemoteLight.ino
1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Name: IrRemoteLight.ino
Created: 5/24/2018 1:10:16 PM
Author: flocki
*/
#include <irremote\IRremote.h>
#include "EEPROMWriteAnything.h"
#include "IRcode.h"
#include "Light.h"
#include <EEPROM\EEPROM.h>
int RECV_pin = 9; //IR receiver port
int pin=10; //light control on port 10 giving signal to uln2003
IRrecv irrecv(RECV_pin);
decode_results results;
IRcode *ircode;
Light *light;
int timeToChangeCode = 500;// setup time after start the board, for change remote IR code
//after this timeToChangeCode time, selected code will be considered as a new code that turns on the light
unsigned long time;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
light = new Light();
ircode = new IRcode();
EEPROM_readAnything(81,ircode->cfg); //read configuration from EEPROM
Serial.println(ircode->cfg.code);
}
void SaveCode(unsigned long code)
{
EEPROM_writeAnything(81, code);
}
// the loop function runs over and over again until power down or reset
void loop() {
time = millis();
if (irrecv.decode(&results))
{
if (time > timeToChangeCode) //enter to setup time(timeToChangeCode) is up - normal work- switch the light
{
Serial.println(results.value, HEX);
Serial.println(results.value);
if (results.value == ircode->cfg.code) //whencode is compatible switch the light
{
if (light->ToggleLight(pin))
{
Serial.println("jasno");
}
else
{
Serial.println("ciemno");
}
}
}
else { //config time has not passed - changing new code is possible by Remote IR
ircode->cfg.code = results.value;
SaveCode(ircode->cfg.code);
Serial.println(time);
}
irrecv.resume(); // Receive the next value
}
}