-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino-RGB.cpp
More file actions
175 lines (162 loc) · 4 KB
/
Arduino-RGB.cpp
File metadata and controls
175 lines (162 loc) · 4 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <Arduino.h>
#include <IRremote.h>
#include <LiquidCrystal.h>
#define redPin A0
#define bluePin A1
#define greenPin A2
#define redBtn 10
#define greenBtn 9
#define blueBtn 8
#define led 36
int RECV_PIN = 11;
IRrecv receiver(RECV_PIN);
decode_results results;
LiquidCrystal lcd(12, 13, 5, 4, 3, 2);
void setup(){
init();
Serial.begin(9600);
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
pinMode(redBtn,INPUT_PULLUP);
pinMode(greenBtn,INPUT_PULLUP);
pinMode(blueBtn,INPUT_PULLUP);
lcd.begin(16, 2);
receiver.enableIRIn();
// set light to white
analogWrite(redPin,255);
analogWrite(bluePin,255);
analogWrite(greenPin,255);
lcd.setCursor(0,0);
lcd.print("RED");
lcd.setCursor(5,0);
lcd.print("GREEN");
lcd.setCursor(12,0);
lcd.print("BLUE");
lcd.setCursor(0,1);
lcd.print("255");
lcd.setCursor(6,1);
lcd.print("255");
lcd.setCursor(12,1);
lcd.print("255");
}
double cursorColor = 0; // 0 is red, 1 is green, 2 is blue
int wordLength = 0; // should not exceed 3
int new_rgb = 0;
void remoteRGB(int number){
lcd.setCursor((cursorColor*6)+wordLength,1);
lcd.print(number);
if (wordLength == 0){
// 100th
new_rgb += 100*number;
}
else if (wordLength == 1){
// 10th
new_rgb += 10*number;
}
else if (wordLength == 2){
// 1th
new_rgb += number;
}
wordLength ++;
if (wordLength == 3){
// met the word length
wordLength = 0;
if (cursorColor == 0){
// is red
Serial.print("changing red to: ");Serial.println(new_rgb);
new_rgb = constrain(new_rgb,0,255);
analogWrite(redPin, new_rgb);
new_rgb = 0;
}
else if (cursorColor == 1){
// is green
Serial.print("changing green to: ");Serial.println(new_rgb);
new_rgb = constrain(new_rgb,0,255);
analogWrite(greenPin, new_rgb);
new_rgb = 0;
}
else if (cursorColor == 2){
// is blue
Serial.print("changing blue to: ");Serial.println(new_rgb);
new_rgb = constrain(new_rgb,0,255);
analogWrite(bluePin, new_rgb);
new_rgb = 0;
}
cursorColor = int(cursorColor + 1)%3; // go to next color
delay(300);
}
}
int main(){
setup();
while(true){
if (receiver.decode(&results)){
if (results.value == 0xFFE01F){
// scroll down
Serial.println("scroll down");
cursorColor = int(cursorColor + 1)%3;
wordLength = 0;
}else if (results.value == 0xFF906F){
// scroll up
Serial.println("scroll up");
cursorColor = int(cursorColor - 1)%3;
wordLength = 0;
}else if (results.value == 0xFD30CF){
// 0
Serial.println("0");
remoteRGB(0);
}else if (results.value == 0xFD08F7){
//1
Serial.println("1");
remoteRGB(1);
}else if (results.value == 0xFD8877){
//2
Serial.println("2");
remoteRGB(2);
}else if (results.value == 0xFD48B7){
//3
Serial.println("3");
remoteRGB(3);
}else if (results.value == 0xFD28D7){
//4
Serial.println("4");
remoteRGB(4);
}else if (results.value == 0xFDA857){
//5
Serial.println("5");
remoteRGB(5);
}else if (results.value == 0xFD6897){
//6
Serial.println("6");
remoteRGB(6);
}else if (results.value == 0xFD18E7){
//7
Serial.println("7");
remoteRGB(7);
}else if (results.value == 0xFD9867){
//8
Serial.println("8");
remoteRGB(8);
}else if (results.value == 0xFD58A7){
//9
Serial.println("9");
remoteRGB(9);
}
receiver.resume();
}
// buttons manage color
if(digitalRead(redBtn)==LOW){
cursorColor = 0;
wordLength = 0;
}
if (digitalRead(greenBtn)==LOW){
cursorColor = 1;
wordLength = 0;
}
if (digitalRead(blueBtn)==LOW){
cursorColor = 2;
wordLength = 0;
}
delay(100);
}
}