-
Notifications
You must be signed in to change notification settings - Fork 1
/
IRLedControl.ino
85 lines (77 loc) · 1.96 KB
/
IRLedControl.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <IRremote.h>
int RECV_PIN = 2;
int redLed = 9;
int greenLed = 10;
int blueLed = 11;
decode_results results;
IRrecv irrecv(RECV_PIN);
// Define IR codes for the remote control buttons
#define CH1 0xFFA25D
#define CH 0xFF629D
#define CH2 0xFFE21D
#define PREV 0xFF22DD
#define NEXT 0xFF02FD
#define PLAYPAUSE 0xFFC23D
#define VOL1 0xFFE01F
#define VOL2 0xFFA857
#define EQ 0xFF906F
#define BUTTON0 0xFF6897
#define BUTTON100 0xFF9867
#define BUTTON200 0xFFB04F
#define BUTTON1 0xFF30CF
#define BUTTON2 0xFF18E7
#define BUTTON3 0xFF7A85
#define BUTTON4 0xFF10EF
#define BUTTON5 0xFF38C7
#define BUTTON6 0xFF5AA5
#define BUTTON7 0xFF42BD
#define BUTTON8 0xFF4AB5
#define BUTTON9 0xFF52AD
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value == BUTTON1) {
digitalWrite(redLed, !digitalRead(redLed));
if (digitalRead(redLed) == HIGH) {
Serial.println("Red is on!");
} else {
Serial.println("Red is off!");
}
}
if (results.value == BUTTON2) {
digitalWrite(greenLed, !digitalRead(greenLed));
if (digitalRead(greenLed) == HIGH) {
Serial.println("Green is on!");
} else {
Serial.println("Green is off!");
}
}
if (results.value == BUTTON3) {
digitalWrite(blueLed, !digitalRead(blueLed));
if (digitalRead(blueLed) == HIGH) {
Serial.println("Blue is on!");
} else {
Serial.println("Blue is off!");
}
}
if (results.value == BUTTON4) {
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);
Serial.println("All LEDs are off!");
}
if (results.value == BUTTON0) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, HIGH);
digitalWrite(blueLed, HIGH);
Serial.println("All LEDs are on!");
}
irrecv.resume();
}
}