1
14
15
16#include <IRremote.h>
17#include <ir_Lego_PF_BitStreamEncoder.h>
18
19#include <Servo.h>
20#include <Keypad.h>
21Servo Srv;
22
23int RECV_PIN = 12;
24float armazenavalor1;
25float armazenavalor2;
26IRrecv irrecv(RECV_PIN);
27decode_results results;
28
29const byte LINHAS = 4;
30const byte COLUNAS = 4;
31
32const char TECLAS_MATRIZ[LINHAS][COLUNAS] = {
33 {'1', '2', '3', 'A'},
34 {'4', '5', '6', 'B'},
35 {'7', '8', '9', 'C'},
36 {'*', '0', '#', 'D'}
37};
38
39const byte PINOS_LINHAS[LINHAS] = {9, 8, 7, 6};
40const byte PINOS_COLUNAS[COLUNAS] = {5, 4, 3, 2};
41Keypad teclado_personalizado = Keypad(makeKeymap(TECLAS_MATRIZ), PINOS_LINHAS, PINOS_COLUNAS, LINHAS, COLUNAS);
42
43int Fora = 50;
44int Dentro = 150;
45
46void setup() {
47Serial.begin(9600);
48pinMode(12,INPUT);
49irrecv.enableIRIn();
50Srv.attach(11);
51delay(250);
52Srv.write(Fora);
53}
54
55void loop() {
56
57char leitura_teclas = teclado_personalizado.getKey();
58 switch (leitura_teclas){
59
60 case '1':
61 pushPull1();
62break;
63
64 case '2':
65 pushPull2();
66 break;
67
68 case '3':
69 pushPull3();
70 break;
71
72 case '4':
73 pushPull4();
74break;
75
76 case '5':
77 pushPull5();
78 break;
79
80 case '6':
81 pushPull6();
82
83 break;
84
85 case '7':
86 pushPull7;
87
88break;
89 case '8':
90 pushPull8();
91 break;
92
93 case '9':
94 pushPull9();
95break;
96
97}
98
99
100
101if (irrecv.decode(&results)) {
102 Serial.print("Valor lido : ");
103 Serial.println(results.value, HEX);
104 armazenavalor1 = (results.value);
105 irrecv.resume();
106 armazenavalor2 = (results.value);
107delay(500);
108
109
110 if (armazenavalor1 == 0xFF30CF ){
111 pushPull1();
112}
113irrecv.resume();
114
115if (armazenavalor1 == 0xFF18E7 ){
116pushPull2();
117}
118irrecv.resume();
119
120if (armazenavalor1 == 0xFF7A85 ){
121pushPull3();
122}
123
124irrecv.resume();
125
126if (armazenavalor1 == 0xFF10EF ){
127pushPull4();
128}
129
130irrecv.resume();
131
132if (armazenavalor1 == 0xFF38C7 ){
133pushPull5();
134}
135
136irrecv.resume();
137
138if (armazenavalor1 == 0xFF5AA5 ){
139pushPull6();
140}
141irrecv.resume();
142
143if (armazenavalor1 == 0xFF42BD ){
144pushPull7();
145}
146irrecv.resume();
147
148if (armazenavalor1 == 0xFF4AB5 ){
149pushPull8();
150}
151
152irrecv.resume();
153
154if (armazenavalor1 == 0xFF52AD ){
155pushPull9();
156}
157
158irrecv.resume();
159
160 }
161}
162
163
164 void pushPull(){
165Srv.write(Dentro);
166 delay(300);
167 Srv.write(Fora);
168 delay(300);
169 }
170
171 void pushPull1() {
172pushPull();
173}
174
175 void pushPull2() {
176pushPull();
177pushPull();
178}
179
180 void pushPull3() {
181pushPull();
182pushPull();
183pushPull();
184}
185
186 void pushPull4() {
187pushPull();
188pushPull();
189pushPull();
190pushPull();
191}
192
193 void pushPull5() {
194pushPull();
195pushPull();
196pushPull();
197pushPull();
198pushPull();
199}
200
201 void pushPull6() {
202pushPull();
203pushPull();
204pushPull();
205pushPull();
206pushPull();
207pushPull();
208}
209
210 void pushPull7() {
211pushPull();
212pushPull();
213pushPull();
214pushPull();
215pushPull();
216pushPull();
217pushPull();
218}
219
220 void pushPull8() {
221pushPull();
222pushPull();
223pushPull();
224pushPull();
225pushPull();
226pushPull();
227pushPull();
228pushPull();
229}
230
231 void pushPull9() {
232pushPull();
233pushPull();
234pushPull();
235pushPull();
236pushPull();
237pushPull();
238pushPull();
239pushPull();
240pushPull();
241 }
242