-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1602_IRremote_Notepad.ino
301 lines (284 loc) · 9.45 KB
/
1602_IRremote_Notepad.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
* 1602 IRremote Notepad for Nano by Bill Jenkins
* Released 09/24/2018
* This prompts user for imput from the IR remote and
* updates the message on a 1602 display accordingly.
* Revised 09/30/2018
* Eliminated bug that caused the opening screen to repeat
* Revised 12/14/2018
* Fitted 1602 display with I2C module, replaced <LiquidCrystal.h>
* with <Wire.h> and <LiquidCrystal_I2C.h>
*
* Key Menu for Arduino IR remote
* '1' Key - Increment char by 2
* '2' Key - Increment char by 4
* '3' Key - Increment char by 8
* '4' Key - Decrement current char
* '5' Key - Clears screen and starts over
* '6' Key - Increment current char
* '7' Key - Decrement current char by 2
* '8' Key - Decrement current char by 4
* '9' Key - Decrement current char by 8
* '*' Key - Add new alpha character
* '0' Key - Add new numeric character
* '#' Key - Add new punctuation character
* UP Key - Decrement current char by 32 (a -> A)
* DOWN Key - Increment current letter by 32 (A -> a)
* RIGHT Key - Add new space character
* LEFT Key - clear current character, go back one character
* OK Key - Locks message, requires reset to continue
*
* Hardware:
* Arduino Nano
* 810 tie point breadboard
* IR Remote and IR Receiver module
* 1602 16x2 character LCD display
* I2C module for 1602
*
* <Wire.h>
* <LiquidCrystal_I2C.h>
* Required Libraries:
* <boarddefs.h>
* <IRremote.h>
* <IRremoteInt.h>
* <ir_Lego_PF_BitStreamEncoder.h>
*/
// Connections for 1602 16x2 character LCD module (to I2C module)
// 1602 I2C
// ------ ------
// 1 VSS Pin 1
// 2 VDD Pin 2
// 3 V0 Pin 3
// 4 RS Pin 4
// 5 RW Pin 5
// 6 E Pin 6
// 7 D0 Pin 7
// 8 D1 Pin 8
// 9 D2 Pin 9
// 10 D3 Pin 10
// 11 D4 Pin 11
// 12 D5 Pin 12
// 13 D6 Pin 13
// 14 D7 Pin 14
// 15 A Pin 15
// 16 K Pin 16
// Connections for I2C Module to Nano
// I2C Nano
// --- ---
// GND Gnd
// VCC +5v
// SDA A4
// SCL A5
// Connections for Infrared Receiver (IRR) module
// IRR Nano
// --- ---
// S D2
// VCC +5v
// GND Gnd
// include required libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
int RECV_PIN = 2; //define IR receiver input pin on Arduino
IRrecv irrecv(RECV_PIN); // declare instance of receive object
decode_results results; // results of key press scan
// blank string to capture Mr. Smiley and Ms. Heart
String sac="Arduino";
char thischar; // current character
char linetext[2][16];
int row, col; // row and column number
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
irrecv.enableIRIn(); // Start the IR receiver
// get ready to process characters
// initialize the LCD
lcd.begin();
lcd.clear();
lcd.backlight();
delay(100);
// print opening screen
lcd.print("IRremote Notepad"); // and display for three
lcd.setCursor(0, 1); // seconds, then clear
lcd.print("by Bill Jenkins"); // the display
delay(3000);
lcd.clear();
row=0;
col=0;
linetext[0][0]='m';
lcd.setCursor(0,0);
lcd.print(linetext[0]);
lcd.setCursor(0,0);
}
void loop()
{
if (irrecv.decode(&results)) // if any key is pressed
{
switch(results.value) // print key press info
{
case 0xFFFFFFFF: // 'Long' indicator,
break; // do nothing
case 0xFFA25D: // '1' pressed
// Decrement character by 2
linetext[row][col]-=2;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFF629D: // '2' pressed
// Decrement character by 4
linetext[row][col]-=4;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFFE21D: // '3' pressed
// Decrement character by 8
linetext[row][col]-=8;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFF22DD: // '4' pressed
// Decrement current char
linetext[row][col]--;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFF02FD: // '5' pressed
// clear all, start from beginning
for (row=0; row<2; row++)
{
for (col=0; col<16; col++)
linetext[row][col]=' ';
}
row=0;
col=0;
lcd.clear();
linetext[row][col]='m';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// new start screen
break;
case 0xFFC23D: // '6' pressed
// Increment character
linetext[row][col]++;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFFE01F: // '7' pressed
// Increment character by 2
linetext[row][col]+=2;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFFA857: // '8' pressed
// Increment character by 4
linetext[row][col]+=4;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFF906F: // '9' pressed
// Increment character by 8
linetext[row][col]+=8;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFF6897: // '*' pressed
// Add an alpha character
col++; // Increment column
if (col>15) // check for overflow
{
if (row==1) // on display overflow
while (1); // stop processing keys
row++;
col=0;
}
linetext[row][col]='m';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print lowercase M
break;
case 0xFF9867: // '0' pressed
// Add a numeric character
col++; // increment colunm
if (col>15) // check for overflow
{
if (row==1) // on display overflow
while (1); // stop processing keys
row++;
col=0;
}
linetext[row][col]='5';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print numeric 5
break;
case 0xFFB04F: // '#' pressed
// Add punctation
col++; // increment colunm
if (col>15) // check for overflow
{
if (row==1) // on display overflow
while (1); // stop processing keys
row++;
col=0;
}
linetext[row][col]='!';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print ! character
break;
case 0xFF18E7: // 'UP' pressed
// Decrement character by 32 (lowercase to Uppercase)
linetext[row][col]-=32;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
case 0xFF10EF: // 'LEFT' pressed
// clear current character, edit previous character
linetext[row][col]=' ';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print space
col--; // Decrement column
if (col<0)
{
row--;
col=15;
}
if (row<0)
{
row=0;
col=0;
linetext[row][col]='m';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print m
}
break;
case 0xFF38C7: // 'OK' pressed
// Freeze screen, disable input
// requires system reset to continue.
while (1);
break;
case 0xFF5AA5: // 'RIGHT' pressed
// Add space character
col++; // increment colunm
if (col>15) // check for overflow
{
if (row==1) // on display overflow
while (1); // stop processing keys
row++;
col=0;
}
linetext[row][col]=' ';
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print space character
break;
case 0xFF4AB5: // 'DOWN' pressed
// Increment character by 32 (Uppercase to lowercase)
linetext[row][col]+=32;
lcd.setCursor(col,row);
lcd.print(linetext[row][col]);// print new character
break;
default: // do nothing
break;
}
irrecv.resume(); // Prepare for key press
}
}