-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir_control_mc220.ino
50 lines (38 loc) · 963 Bytes
/
ir_control_mc220.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
#include <IRremote.h>
int RECV_PIN = PD2;
int RELAY_PIN = PD4;
int SWITCH_PIN = PD6;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long last = millis();
bool on = false;
bool switchLast = true;
void setup() {
irrecv.enableIRIn(); // Start the receiver
pinMode(RELAY_PIN,OUTPUT);
pinMode(SWITCH_PIN, INPUT);
switchLast = digitalRead(SWITCH_PIN);
//Serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results))
{
if(results.value == 0x54C || results.value == 0xD4C || results.value == 0x44C || results.value == 0xC4C)
{
if (millis() - last > 250) {
on = !on;
digitalWrite(RELAY_PIN, on ? HIGH : LOW);
// Serial.println(on);
}
}
last = millis();
irrecv.resume(); // Receive the next value
}
if(digitalRead(SWITCH_PIN) != switchLast)
{
switchLast = !switchLast;
on = !on;
digitalWrite(RELAY_PIN, on ? HIGH : LOW);
// Serial.println(on);
}
}