Arduino-LCD
LCD library for Arduino
Benchmark.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "TWI.h"
3 #include "Software/TWI.h"
4 #include "Hardware/TWI.h"
5 #include "LCD.h"
6 #include "Driver/PCD8544.h"
7 #include "Driver/HD44780.h"
8 #include "Adapter/PP7W.h"
9 #include "Adapter/SR3W.h"
10 #include "Adapter/SR4W.h"
11 #include "Adapter/MJKDZ.h"
12 #include "Adapter/GY_IICLCD.h"
13 #include "Adapter/DFRobot_IIC.h"
14 #include "Shield/LCD4884.h"
15 #include "Shield/LCD_Keypad.h"
16 
17 
18 // Configure: HD44780 Adapter; PP7W, SR3W, SR4W or TWI PCF8574
19 // LCD::PP7W<BOARD::D4, BOARD::D5, BOARD::D6, BOARD::D7, BOARD::D8, BOARD::D9, BOARD::D10> io;
20 // LCD::SR3W<BOARD::D7, BOARD::D6, BOARD::D5> io;
21 // LCD::SR4W<BOARD::D7, BOARD::D6, BOARD::D5, BOARD::D4> io;
22 // Software::TWI<BOARD::D8, BOARD::D9> twi;
23 // Software::TWI<BOARD::D18, BOARD::D19> twi;
24 // Hardware::TWI twi(100000UL);
25 // Hardware::TWI twi(400000UL);
26 // LCD::MJKDZ io(twi);
27 // LCD::GY_IICLCD io(twi);
28 // LCD::DFRobot_IIC io(twi);
29 
30 // Configure: HD44780, PCD8544, LCD4884 or LCD Keypad
31 // HD44780 lcd(io);
32 // PCD8544<BOARD::D5, BOARD::D4, BOARD::D3, BOARD::D2> lcd;
33 // LCD4884 lcd;
35 
36 #define MEASURE(expr) \
37  do { \
38  Serial.flush(); \
39  start = micros(); \
40  expr; \
41  stop = micros(); \
42  Serial.print(nr++); \
43  Serial.print(F(": " #expr ": ")); \
44  Serial.println(stop - start); \
45  delay(500); \
46  lcd.display_clear(); \
47  } while (0)
48 
50 {
51  for (int h = 0; h < lcd.HEIGHT; h++)
52  for (int w = 0; w < lcd.WIDTH; w++)
53  lcd.print((char) ('A' + w));
54 }
55 
56 void setup()
57 {
58  Serial.begin(57600);
59  while (!Serial);
60 }
61 
62 void loop()
63 {
64  uint32_t start, stop;
65  uint16_t nr = 0;
66 
67  // Character and String print
68  MEASURE(lcd.begin());
69  MEASURE(lcd.write('0'));
70  MEASURE(lcd.print('0'));
71  MEASURE(lcd.print("0"));
72  MEASURE(lcd.print("10"));
73  MEASURE(lcd.print("100"));
74  MEASURE(lcd.print("1000"));
75  MEASURE(lcd.print("10000"));
76  MEASURE(lcd.print("Hello World"));
77  MEASURE(lcd.print(F("Hello World")));
78  MEASURE(lcd.print(F("\aHello World\a")));
79  MEASURE(lcd.print(F("Hello\tWorld")));
80  MEASURE(lcd.print(F("Hello\nWorld")));
81  MEASURE(lcd.print(F("\nHello\tWorld")));
83 
84  // Integer print
85  MEASURE(lcd.print(0));
86  MEASURE(lcd.print(1));
87  MEASURE(lcd.print(10));
88  MEASURE(lcd.print(100));
89  MEASURE(lcd.print(INT16_MIN));
90  MEASURE(lcd.print(INT16_MAX));
91  MEASURE(lcd.print(INT32_MIN));
92  MEASURE(lcd.print(INT32_MAX));
93 
94  // Float print
95  MEASURE(lcd.print(1234.56789, 5));
96  MEASURE(lcd.print(-1234.56789, 5));
97 
98  // Integer print in base
99  MEASURE(lcd.print(0x8000, BIN));
100  MEASURE(lcd.print(0x8000, DEC));
101  MEASURE(lcd.print(0x8000, HEX));
102 
103  // Special functions
104  MEASURE(lcd.backlight_off());
105  MEASURE(lcd.backlight_on());
106  MEASURE(lcd.display_off());
107  MEASURE(lcd.display_on());
108  MEASURE(lcd.display_normal());
109  MEASURE(lcd.display_inverse());
110  MEASURE(lcd.display_clear());
111  MEASURE(lcd.cursor_blink_on());
112  MEASURE(lcd.cursor_blink_off());
113  MEASURE(lcd.cursor_set(0,0));
114  MEASURE(lcd.cursor_home());
115 
116  // Special characters
117  MEASURE(lcd.print('\a'));
118  MEASURE(lcd.print('\b'));
119  MEASURE(lcd.print('\f'));
120  MEASURE(lcd.print('\n'));
121  MEASURE(lcd.print('\r'));
122  MEASURE(lcd.print('\t'));
123 
124  // HD44780 specific
125 #if !defined(PCD8544_H)
128  MEASURE(lcd.cursor_blink_on());
129  MEASURE(lcd.cursor_blink_off());
130 #endif
131 
132  // That all in this benchmark
133  MEASURE(lcd.end());
134  Serial.println();
135 }
136 
137 /*
138 --------------------------------------------------------------------------------
139 Arduino Leonardo
140 LCD::PP7W<> io;
141 HD44780 lcd(io);
142 --------------------------------------------------------------------------------
143 0: lcd.begin(): 54820
144 1: lcd.write('0'): 44
145 2: lcd.print('0'): 44
146 3: lcd.print("0"): 52
147 4: lcd.print("10"): 92
148 5: lcd.print("100"): 136
149 6: lcd.print("1000"): 180
150 7: lcd.print("10000"): 228
151 8: lcd.print("Hello World"): 496
152 9: lcd.print(F("Hello World")): 496
153 10: lcd.print(F("\aHello World\a")): 500
154 11: lcd.print(F("Hello\tWorld")): 492
155 12: lcd.print(F("Hello\nWorld")): 1216
156 13: lcd.print(F("\nHello\tWorld")): 1276
157 14: fill_screen(): 2176
158 15: lcd.print(0): 96
159 16: lcd.print(1): 96
160 17: lcd.print(10): 176
161 18: lcd.print(100): 268
162 19: lcd.print(INT16_MIN): 464
163 20: lcd.print(INT16_MAX): 432
164 21: lcd.print(INT32_MIN): 884
165 22: lcd.print(INT32_MAX): 844
166 23: lcd.print(1234.56789, 5): 1028
167 24: lcd.print(-1234.56789, 5): 1068
168 25: lcd.print(0x8000, BIN): 1320
169 26: lcd.print(0x8000, DEC): 424
170 27: lcd.print(0x8000, HEX): 340
171 28: lcd.backlight_off(): 4
172 29: lcd.backlight_on(): 8
173 30: lcd.display_off(): 40
174 31: lcd.display_on(): 40
175 32: lcd.display_normal(): 0
176 33: lcd.display_inverse(): 4
177 34: lcd.display_clear(): 1668
178 35: lcd.cursor_blink_on(): 40
179 36: lcd.cursor_blink_off(): 40
180 37: lcd.cursor_set(0,0): 44
181 38: lcd.cursor_home(): 1660
182 39: lcd.print('\a'): 8
183 40: lcd.print('\b'): 132
184 41: lcd.print('\f'): 1656
185 42: lcd.print('\n'): 784
186 43: lcd.print('\r'): 48
187 44: lcd.print('\t'): 52
188 45: lcd.end(): 40
189 --------------------------------------------------------------------------------
190 Arduino Pro Mini
191 LCD::SR4W<> io;
192 HD44780 lcd(io);
193 --------------------------------------------------------------------------------
194 0: lcd.begin(): 49828
195 1: lcd.write('0'): 56
196 2: lcd.print('0'): 48
197 3: lcd.print("0"): 56
198 4: lcd.print("10"): 100
199 5: lcd.print("100"): 148
200 6: lcd.print("1000"): 196
201 7: lcd.print("10000"): 248
202 8: lcd.print("Hello World"): 520
203 9: lcd.print(F("Hello World")): 516
204 10: lcd.print(F("\aHello World\a")): 520
205 11: lcd.print(F("Hello\tWorld")): 520
206 12: lcd.print(F("Hello\nWorld")): 1304
207 13: lcd.print(F("\nHello\tWorld")): 1352
208 14: fill_screen(): 2324
209 15: lcd.print(0): 100
210 16: lcd.print(1): 96
211 17: lcd.print(10): 184
212 18: lcd.print(100): 268
213 19: lcd.print(INT16_MIN): 492
214 20: lcd.print(INT16_MAX): 436
215 21: lcd.print(INT32_MIN): 912
216 22: lcd.print(INT32_MAX): 868
217 23: lcd.print(1234.56789, 5): 1052
218 24: lcd.print(-1234.56789, 5): 1100
219 25: lcd.print(0x8000, BIN): 1360
220 26: lcd.print(0x8000, DEC): 432
221 27: lcd.print(0x8000, HEX): 348
222 28: lcd.backlight_off(): 8
223 29: lcd.backlight_on(): 4
224 30: lcd.display_off(): 44
225 31: lcd.display_on(): 44
226 32: lcd.display_normal(): 4
227 33: lcd.display_inverse(): 4
228 34: lcd.display_clear(): 1648
229 35: lcd.cursor_blink_on(): 44
230 36: lcd.cursor_blink_off(): 44
231 37: lcd.cursor_set(0,0): 48
232 38: lcd.cursor_home(): 1648
233 39: lcd.print('\a'): 4
234 40: lcd.print('\b'): 144
235 41: lcd.print('\f'): 1656
236 42: lcd.print('\n'): 836
237 43: lcd.print('\r'): 52
238 44: lcd.print('\t'): 56
239 45: lcd.end(): 44
240 --------------------------------------------------------------------------------
241 Arduino Pro Mini
242 LCD::SR3W<> io;
243 HD44780 lcd(io);
244 --------------------------------------------------------------------------------
245 0: lcd.begin(): 54840
246 1: lcd.write('0'): 60
247 2: lcd.print('0'): 60
248 3: lcd.print("0"): 68
249 4: lcd.print("10"): 124
250 5: lcd.print("100"): 184
251 6: lcd.print("1000"): 240
252 7: lcd.print("10000"): 296
253 8: lcd.print("Hello World"): 656
254 9: lcd.print(F("Hello World")): 648
255 10: lcd.print(F("\aHello World\a")): 656
256 11: lcd.print(F("Hello\tWorld")): 660
257 12: lcd.print(F("Hello\nWorld")): 1636
258 13: lcd.print(F("\nHello\tWorld")): 1700
259 14: fill_screen(): 2920
260 15: lcd.print(0): 116
261 16: lcd.print(1): 112
262 17: lcd.print(10): 208
263 18: lcd.print(100): 300
264 19: lcd.print(INT16_MIN): 560
265 20: lcd.print(INT16_MAX): 504
266 21: lcd.print(INT32_MIN): 1044
267 22: lcd.print(INT32_MAX): 984
268 23: lcd.print(1234.56789, 5): 1168
269 24: lcd.print(-1234.56789, 5): 1232
270 25: lcd.print(0x8000, BIN): 1548
271 26: lcd.print(0x8000, DEC): 492
272 27: lcd.print(0x8000, HEX): 396
273 28: lcd.backlight_off(): 4
274 29: lcd.backlight_on(): 4
275 30: lcd.display_off(): 56
276 31: lcd.display_on(): 56
277 32: lcd.display_normal(): 4
278 33: lcd.display_inverse(): 4
279 34: lcd.display_clear(): 1668
280 35: lcd.cursor_blink_on(): 52
281 36: lcd.cursor_blink_off(): 56
282 37: lcd.cursor_set(0,0): 56
283 38: lcd.cursor_home(): 1668
284 39: lcd.print('\a'): 4
285 40: lcd.print('\b'): 184
286 41: lcd.print('\f'): 1672
287 42: lcd.print('\n'): 1044
288 43: lcd.print('\r'): 60
289 44: lcd.print('\t'): 68
290 45: lcd.end(): 56
291 --------------------------------------------------------------------------------
292 Arduino Uno
293 Software::TWI<BOARD::D18, BOARD::D19> twi;
294 LCD::GY_IICLCD io(twi);
295 HD44780 lcd(io);
296 --------------------------------------------------------------------------------
297 0: lcd.begin(): 58160
298 1: lcd.write('0'): 496
299 2: lcd.print('0'): 496
300 3: lcd.print("0"): 496
301 4: lcd.print("10"): 992
302 5: lcd.print("100"): 1484
303 6: lcd.print("1000"): 1976
304 7: lcd.print("10000"): 2468
305 8: lcd.print("Hello World"): 5424
306 9: lcd.print(F("Hello World")): 5408
307 10: lcd.print(F("\aHello World\a")): 5420
308 11: lcd.print(F("Hello\tWorld")): 5420
309 12: lcd.print(F("Hello\nWorld")): 13756
310 13: lcd.print(F("\nHello\tWorld")): 14260
311 14: fill_screen(): 24568
312 15: lcd.print(0): 540
313 16: lcd.print(1): 548
314 17: lcd.print(10): 1072
315 18: lcd.print(100): 1608
316 19: lcd.print(INT16_MIN): 3156
317 20: lcd.print(INT16_MAX): 2668
318 21: lcd.print(INT32_MIN): 5808
319 22: lcd.print(INT32_MAX): 5320
320 23: lcd.print(1234.56789, 5): 5504
321 24: lcd.print(-1234.56789, 5): 5988
322 25: lcd.print(0x8000, BIN): 8480
323 26: lcd.print(0x8000, DEC): 2664
324 27: lcd.print(0x8000, HEX): 2132
325 28: lcd.backlight_off(): 212
326 29: lcd.backlight_on(): 208
327 30: lcd.display_off(): 484
328 31: lcd.display_on(): 484
329 32: lcd.display_normal(): 4
330 33: lcd.display_inverse(): 4
331 34: lcd.display_clear(): 2096
332 35: lcd.cursor_blink_on(): 492
333 36: lcd.cursor_blink_off(): 488
334 37: lcd.cursor_set(0,0): 488
335 38: lcd.cursor_home(): 2096
336 39: lcd.print('\a'): 4
337 40: lcd.print('\b'): 1472
338 41: lcd.print('\f'): 2100
339 42: lcd.print('\n'): 8836
340 43: lcd.print('\r'): 492
341 44: lcd.print('\t'): 504
342 45: lcd.end(): 492
343 --------------------------------------------------------------------------------
344 Arduino Uno
345 Hardware::TWI twi(100000UL);
346 LCD::GY_IICLCD io(twi);
347 HD44780 lcd(io);
348 --------------------------------------------------------------------------------
349 0: lcd.begin(): 58384
350 1: lcd.write('0'): 516
351 2: lcd.print('0'): 520
352 3: lcd.print("0"): 528
353 4: lcd.print("10"): 1044
354 5: lcd.print("100"): 1560
355 6: lcd.print("1000"): 2080
356 7: lcd.print("10000"): 2596
357 8: lcd.print("Hello World"): 5708
358 9: lcd.print(F("Hello World")): 5700
359 10: lcd.print(F("\aHello World\a")): 5720
360 11: lcd.print(F("Hello\tWorld")): 5720
361 12: lcd.print(F("Hello\nWorld")): 14524
362 13: lcd.print(F("\nHello\tWorld")): 15036
363 14: fill_screen(): 25896
364 15: lcd.print(0): 568
365 16: lcd.print(1): 572
366 17: lcd.print(10): 1128
367 18: lcd.print(100): 1684
368 19: lcd.print(INT16_MIN): 3308
369 20: lcd.print(INT16_MAX): 2812
370 21: lcd.print(INT32_MIN): 6096
371 22: lcd.print(INT32_MAX): 5580
372 23: lcd.print(1234.56789, 5): 5764
373 24: lcd.print(-1234.56789, 5): 6280
374 25: lcd.print(0x8000, BIN): 8912
375 26: lcd.print(0x8000, DEC): 2796
376 27: lcd.print(0x8000, HEX): 2232
377 28: lcd.backlight_off(): 228
378 29: lcd.backlight_on(): 228
379 30: lcd.display_off(): 512
380 31: lcd.display_on(): 520
381 32: lcd.display_normal(): 0
382 33: lcd.display_inverse(): 4
383 34: lcd.display_clear(): 2120
384 35: lcd.cursor_blink_on(): 512
385 36: lcd.cursor_blink_off(): 516
386 37: lcd.cursor_set(0,0): 520
387 38: lcd.cursor_home(): 2124
388 39: lcd.print('\a'): 4
389 40: lcd.print('\b'): 1560
390 41: lcd.print('\f'): 2128
391 42: lcd.print('\n'): 9320
392 43: lcd.print('\r'): 520
393 44: lcd.print('\t'): 524
394 45: lcd.end(): 516
395 --------------------------------------------------------------------------------
396 Hardware::TWI twi(400000UL);
397 LCD::GY_IICLCD io(twi);
398 HD44780 lcd(io);
399 --------------------------------------------------------------------------------
400 0: lcd.begin(): 55896
401 1: lcd.write('0'): 176
402 2: lcd.print('0'): 180
403 3: lcd.print("0"): 184
404 4: lcd.print("10"): 356
405 5: lcd.print("100"): 528
406 6: lcd.print("1000"): 704
407 7: lcd.print("10000"): 880
408 8: lcd.print("Hello World"): 1924
409 9: lcd.print(F("Hello World")): 1928
410 10: lcd.print(F("\aHello World\a")): 1932
411 11: lcd.print(F("Hello\tWorld")): 1932
412 12: lcd.print(F("Hello\nWorld")): 4896
413 13: lcd.print(F("\nHello\tWorld")): 5080
414 14: fill_screen(): 8736
415 15: lcd.print(0): 224
416 16: lcd.print(1): 228
417 17: lcd.print(10): 436
418 18: lcd.print(100): 656
419 19: lcd.print(INT16_MIN): 1256
420 20: lcd.print(INT16_MAX): 1076
421 21: lcd.print(INT32_MIN): 2316
422 22: lcd.print(INT32_MAX): 2148
423 23: lcd.print(1234.56789, 5): 2332
424 24: lcd.print(-1234.56789, 5): 2504
425 25: lcd.print(0x8000, BIN): 3404
426 26: lcd.print(0x8000, DEC): 1072
427 27: lcd.print(0x8000, HEX): 864
428 28: lcd.backlight_off(): 84
429 29: lcd.backlight_on(): 88
430 30: lcd.display_off(): 172
431 31: lcd.display_on(): 168
432 32: lcd.display_normal(): 4
433 33: lcd.display_inverse(): 4
434 34: lcd.display_clear(): 1776
435 35: lcd.cursor_blink_on(): 168
436 36: lcd.cursor_blink_off(): 180
437 37: lcd.cursor_set(0,0): 176
438 38: lcd.cursor_home(): 1776
439 39: lcd.print('\a'): 4
440 40: lcd.print('\b'): 532
441 41: lcd.print('\f'): 1788
442 42: lcd.print('\n'): 3160
443 43: lcd.print('\r'): 180
444 44: lcd.print('\t'): 184
445 45: lcd.end(): 172
446 --------------------------------------------------------------------------------
447 Arduino Uno
448 PCD8544<> lcd;
449 --------------------------------------------------------------------------------
450 0: lcd.begin(): 4388
451 1: lcd.write('0'): 64
452 2: lcd.print('0'): 68
453 3: lcd.print("0"): 80
454 4: lcd.print("10"): 136
455 5: lcd.print("100"): 208
456 6: lcd.print("1000"): 272
457 7: lcd.print("10000"): 332
458 8: lcd.print("Hello World"): 716
459 9: lcd.print(F("Hello World")): 720
460 10: lcd.print(F("\aHello World\a")): 744
461 11: lcd.print(F("Hello\tWorld")): 684
462 12: lcd.print(F("Hello\nWorld")): 1424
463 13: lcd.print(F("\nHello\tWorld")): 1448
464 14: fill_screen(): 9252
465 15: lcd.print(0): 120
466 16: lcd.print(1): 116
467 17: lcd.print(10): 224
468 18: lcd.print(100): 328
469 19: lcd.print(INT16_MIN): 592
470 20: lcd.print(INT16_MAX): 532
471 21: lcd.print(INT32_MIN): 1112
472 22: lcd.print(INT32_MAX): 1048
473 23: lcd.print(1234.56789, 5): 1236
474 24: lcd.print(-1234.56789, 5): 1296
475 25: lcd.print(0x8000, BIN): 2428
476 26: lcd.print(0x8000, DEC): 528
477 27: lcd.print(0x8000, HEX): 428
478 28: lcd.backlight_off(): 4
479 29: lcd.backlight_on(): 4
480 30: lcd.display_off(): 12
481 31: lcd.display_on(): 12
482 32: lcd.display_normal(): 12
483 33: lcd.display_inverse(): 12
484 34: lcd.display_clear(): 4332
485 35: lcd.cursor_blink_on(): 4
486 36: lcd.cursor_blink_off(): 4
487 37: lcd.cursor_set(0,0): 24
488 38: lcd.cursor_home(): 28
489 39: lcd.print('\a'): 8
490 40: lcd.print('\b'): 88
491 41: lcd.print('\f'): 4340
492 42: lcd.print('\n'): 764
493 43: lcd.print('\r'): 32
494 44: lcd.print('\t'): 36
495 45: lcd.end(): 4340
496 --------------------------------------------------------------------------------
497 */
LCD_Keypad lcd
Definition: Benchmark.ino:34
virtual bool begin()
Definition: HD44780.h:132
virtual void display_inverse()
Definition: LCD.h:101
virtual size_t write(uint8_t c)
Definition: HD44780.h:368
virtual void display_on()
Definition: HD44780.h:194
void cursor_underline_on()
Definition: HD44780.h:288
#define MEASURE(expr)
Definition: Benchmark.ino:36
virtual void cursor_blink_off()
Definition: HD44780.h:234
void loop()
Definition: Benchmark.ino:62
virtual void display_clear()
Definition: HD44780.h:212
void fill_screen()
Definition: Benchmark.ino:49
virtual void cursor_set(uint8_t x, uint8_t y)
Definition: HD44780.h:245
const uint8_t HEIGHT
Definition: HD44780.h:106
virtual void cursor_blink_on()
Definition: HD44780.h:225
virtual void backlight_off()
Definition: HD44780.h:185
virtual bool end()
Definition: LCD.h:52
void setup()
Definition: Benchmark.ino:56
virtual void display_normal()
Definition: LCD.h:95
void cursor_underline_off()
Definition: HD44780.h:297
virtual void display_off()
Definition: HD44780.h:203
virtual void backlight_on()
Definition: HD44780.h:176
const uint8_t WIDTH
Definition: HD44780.h:103
virtual void cursor_home()
Definition: HD44780.h:259