├── LICENSE
├── README.md
├── examples
├── Autoscroll
│ └── Autoscroll.ino
├── CompleteTest
│ └── CompleteTest.ino
├── CustomChars
│ └── CustomChars.ino
├── HelloWorld
│ └── HelloWorld.ino
├── Histogram
│ └── Histogram.ino
├── HorizontalBarGraph
│ └── HorizontalBarGraph.ino
├── HorizontalLineGraph
│ └── HorizontalLineGraph.ino
├── MultipleLcd
│ └── MultipleLcd.ino
├── README.md
├── Scroll
│ └── Scroll.ino
├── SerialDisplay
│ └── SerialDisplay.ino
└── VerticalBarGraph
│ └── VerticalBarGraph.ino
├── extras
├── hardware
│ ├── 1602_I2C_LCD_Display.url
│ ├── Blue_2004_I2C_LCD_Display.url
│ ├── I2C_Serial_LCD_Converter_Board_1602_2004.url
│ └── Yellow_Green_2004_I2C_LCD_Display.url
└── info
│ ├── 2004_I2C_Serial_LCD_Display.jpg
│ ├── 2004_Pinout.jpg
│ ├── Arduino I2C LCD.url
│ ├── Arduino LCD API.url
│ ├── Character_Set.jpg
│ ├── Chinese_I2C_Serial_LCD_Converter_Board_1602_2004.jpg
│ └── readme.txt
├── keywords.txt
├── library.properties
└── src
├── LiquidCrystal_I2C.cpp
└── LiquidCrystal_I2C.h
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015-2016 Libor Gabaj
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # LiquidCrystal_I2C
3 | It is the reimplementation of the standard Arduino LCD library, configured to work with parallel HD44780 compatible LCDs, and interfaced via a Chinese PCF8574 I2C serial extender.
4 |
5 |
6 |
7 | ## Credit
8 | The reimplementation has been inspired by and credit goes to:
9 |
10 | - Mario H. atmega@xs4all.nl LiquidCrystal_I2C V2.0
11 | - Murray R. Van Luyn vanluynm@iinet.net.au Mods for Chinese I2C converter board
12 |
13 |
14 |
15 | ## Dependency
16 | The library class extends the system library *Print* and includes following sytem header files.
17 |
18 | - **inttypes.h**: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.
19 | - **Print.h**: Base class that provides *print()* and *println()*.
20 | - **Wire.h**: TWI/I2C library for Arduino & Wiring.
21 |
22 |
23 |
24 | ## Interface
25 | Some of listed functions come out of Arduino [LCD API 1.0](http://playground.arduino.cc/Code/LCDAPI), some of them are specific for this library. It is possible to use functions from the system library [Print](#dependency), which is extended by the *LiquidCrystal_I2C*.
26 |
27 | *) The function is an alias of another (usually previous) one.
28 |
29 | ##### Initialization
30 | - [LiquidCrystal_I2C()](#LiquidCrystal_I2C)
31 | - [begin()](#begin)
32 | - [init()](#init)
33 | - [clear()](#clear)
34 | - [home()](#home)
35 |
36 | ##### Printing
37 | - [print()](#print)
38 | - [write()](#write)
39 |
40 | ##### Display control
41 | - [noDisplay()](#noDisplay)
42 | - *[off()](#noDisplay)
43 | - [display()](#display)
44 | - *[on()](#display)
45 | - [scrollDisplayLeft()](#scrollDisplayLeft)
46 | - [scrollDisplayRight()](#scrollDisplayRight)
47 | - [leftToRight()](#leftToRight)
48 | - [rightToLeft()](#rightToLeft)
49 | - [noAutoscroll()](#noAutoscroll)
50 | - [autoscroll()](#autoscroll)
51 | - [noBacklight()](#noBacklight)
52 | - [backlight()](#backlight)
53 | - *[setBacklight()](#backlight)
54 |
55 | ##### Cursor manipulation
56 | - [noCursor()](#noCursor)
57 | - *[cursor_off()](#noCursor)
58 | - [cursor()](#cursor)
59 | - *[cursor_on()](#cursor)
60 | - [noBlink()](#noBlink)
61 | - *[blink_off()](#noBlink)
62 | - [blink()](#blink)
63 | - *[blink_on()](#blink)
64 | - [setCursor()](#setCursor)
65 |
66 | ##### Graphs
67 | - [init_bargraph()](#init_bargraph)
68 | - [draw_horizontal_graph()](#draw_horizontal_graph)
69 | - [draw_vertical_graph()](#draw_vertical_graph)
70 |
71 | ##### Utilities
72 | - [createChar()](#createChar)
73 | - *[load_custom_character()](#createChar)
74 | - [command()](#command)
75 |
76 |
77 |
78 | ## LiquidCrystal_I2C()
79 | #### Description
80 | Constructor of the object controlling an LCD. It defines address of the LCD and its geometry.
81 |
82 | - More LCDs can be connected to the same I2C bus if they are hardware configured for different addresses.
83 | - For each of LCDs the separate object has to be created.
84 | - When the display powers up, it is configured as follows:
85 |
86 | 1. Display clear
87 | 1. Function set:
88 | - DL = 1; 8-bit interface data
89 | - N = 0; 1-line display
90 | - F = 0; 5x8 dot character font
91 | 1. Display on/off control:
92 | - D = 0; Display off
93 | - C = 0; Cursor off
94 | - B = 0; Blinking off
95 | 1. Entry mode set:
96 | - I/D = 1; Increment by 1
97 | - S = 0; No shift
98 |
99 | - Note, however, that resetting the Arduino does not reset the LCD, so we cannot assume that it is in that state when a sketch starts (and the constructor is called).
100 |
101 | #### Syntax
102 | LiquidCrystal_I2C(uint8_t addr, uint8_t cols, uint8_t rows);
103 |
104 | #### Parameters
105 | - **addr**: I2C addres of the LCD predefined by the serial extender.
106 | - *Valid values*: unsigned byte
107 | - *Default value*: none
108 | - *Usual values*:
109 | - **0x3F** for LCDs *2004* with 20 columns and 4 rows.
110 | - **0x27** for LCDs *1602* with 16 columns and 2 rows.
111 |
112 |
113 |
114 | - **cols**: Number of characters in a row defined by the hardware construction of the LCD screen.
115 | - *Valid values*: unsigned byte
116 | - *Default value*: none
117 | - *Usual values*: 20, 16, 8
118 |
119 |
120 |
121 | - **rows**: Number of rows in the LCD screen defined by the hardware construction of the LCD.
122 | - *Valid values*: unsigned byte
123 | - *Default value*: none
124 | - *Usual values*: 4, 2, 1
125 |
126 | #### Returns
127 | - **LCD object**: Object controlling the LCD communicating at defined address.
128 |
129 | #### Example
130 |
131 | ``` cpp
132 | lcd = LiquidCrystal_I2C(0x27, 16, 2);
133 | ```
134 |
135 | [Back to interface](#interface)
136 |
137 |
138 |
139 | ## begin()
140 | #### Description
141 | Initialize the LCD with its specific geometry parameters.
142 |
143 | #### Syntax
144 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
145 |
146 | #### Parameters
147 | - **cols**: Number of characters in a row defined by the hardware construction of the LCD screen.
148 | - *Valid values*: unsigned byte
149 | - *Default value*: none
150 | - *Usual values*: 20, 16, 8
151 |
152 |
153 | - **rows**: Number of rows in the LCD screen defined by the hardware construction of the LCD.
154 | - *Valid values*: unsigned byte
155 | - *Default value*: none
156 | - *Usual values*: 4, 2, 1
157 |
158 |
159 | - **charsize**: Geometry of the LCD's character defined by a library constant.
160 | - *Valid values*: unsigned byte LCD_5x8DOTS, LCD_5x10DOT
161 | - *Default value*: LCD_5x8DOTS
162 |
163 | #### Returns
164 | None
165 |
166 | #### See also
167 | [LiquidCrystal_I2C()](#LiquidCrystal_I2C)
168 |
169 | [init()](#init)
170 |
171 | [Back to interface](#interface)
172 |
173 |
174 |
175 | ## init()
176 | #### Description
177 | Initializes the display with values put to the [constructor](LiquidCrystal_I2C), clears the screen, and puts cursor to the upper left corner of the screen, i.e., to the home position 0,0. It is a wrapper function for function [begin()](#begin) with forgoing initialization of [Wire](#dependecy) library.
178 |
179 | #### Syntax
180 | void init();
181 |
182 | #### Parameters
183 | None
184 |
185 | #### Returns
186 | None
187 |
188 | #### See also
189 | [LiquidCrystal_I2C()](#LiquidCrystal_I2C)
190 |
191 | [begin()](#begin)
192 |
193 | [Back to interface](#interface)
194 |
195 |
196 |
197 | ## clear()
198 | #### Description
199 | Overloaded function for clearing the entire LCD screen or just a part of a row.
200 | - Using the function without any parameters clears the entire srceen.
201 | - For clearing the entire row use the function just with the first parameter.
202 | - The functions sets the cursor to the start column and row after clearing, i.e., after calling without parameters to the home position (0, 0), or after calling with parameters to the starts of cleared row segment.
203 |
204 | #### Syntax
205 | void clear();
206 | void clear(uint8_t rowStart, uint8_t colStart = 0, uint8_t colCnt = 255);
207 |
208 | #### Parameters
209 | - **rowStart**: Number of a row to be cleared counting from 0.
210 | - *Valid values*: unsigned byte 0 to [rows - 1](#prm_rows) of the [constructor](#LiquidCrystal_I2C)
211 | - *Default value*: none
212 |
213 |
214 | - **colStart**: Order number of the first character in a cleared row counting from 0, which the cleared segment starts from.
215 | - *Valid values*: unsigned byte 0 to [cols - 1](#prm_cols) of the [constructor](#LiquidCrystal_I2C)
216 | - *Default value*: 0 (start of a row)
217 |
218 |
219 | - **colCnt**: Number of cleared characters in a cleard row.
220 | - *Valid values*: unsigned byte 0 to [cols](#prm_cols) of the [constructor](#LiquidCrystal_I2C)
221 | - *Default value*: 255, but internally limited to (*cols* - *colStart*)
222 |
223 | #### Returns
224 | None
225 |
226 | #### See also
227 | [LiquidCrystal_I2C()](#LiquidCrystal_I2C)
228 |
229 | [Back to interface](#interface)
230 |
231 |
232 |
233 | ## home()
234 | #### Description
235 | Places the cursor to the home position (0, 0) and leaves displayed characters.
236 |
237 | #### Syntax
238 | void init();
239 |
240 | #### Parameters
241 | None
242 |
243 | #### Returns
244 | None
245 |
246 | #### See also
247 | [LiquidCrystal_I2C()](#LiquidCrystal_I2C)
248 |
249 | [clear()](#clear)
250 |
251 | [Back to interface](#interface)
252 |
253 |
254 |
255 | ## print()
256 | #### Description
257 | Prints text or number to the LCD. It is inhereted function from the parent system one. The function is overloaded and acts according the data type of the input data to be printed.
258 |
259 | #### Syntax
260 | byte print(char|byte|int|long|string data, int base);
261 |
262 | #### Parameters
263 | - **data**: String or number that should be printed on the LCD from current cursor position.
264 | - *Valid values*: arbitrary
265 | - *Default value*: none
266 |
267 |
268 | - **base**: Optional base in which to print numbers.
269 | - *Valid values*: integer in form of preprocesor constants
270 | - BIN: binary base 2
271 | - DEC: decimal base 10
272 | - OCT: octal base 8
273 | - HEX hexadecimal base 16
274 | - *Default value*: string
275 |
276 | #### Returns
277 | - **ProcessBytes**: Number of successfully printed bytes.
278 |
279 | #### Example
280 |
281 | ``` cpp
282 | lcd = LiquidCrystal_I2C(0x27, 16, 2);
283 | void setup()
284 | {
285 | lcd.print("Hello, world!");
286 | lcd.setCursor(0, 1);
287 | lcd.print(128, HEX);
288 | }
289 |
290 | void loop() {}
291 | ```
292 | >Hello, world!
293 | >80
294 |
295 |
296 | #### See also
297 | [write()](#write)
298 |
299 | [setCursor()](#setCursor)
300 |
301 | [LiquidCrystal_I2C()](#LiquidCrystal_I2C)
302 |
303 | [Back to interface](#interface)
304 |
305 |
306 |
307 | ## write()
308 | #### Description
309 | Writes a raw value to the display.
310 |
311 | #### Syntax
312 | size_t write(uint8_t value);
313 |
314 | #### Parameters
315 | - **value**: Value that should be write to the LCD at address set before.
316 | - *Valid values*: unsigned byte
317 | - *Default value*: none
318 |
319 | #### Returns
320 | - **ProcessBytes**: Number of successfully processed bytes; always 1.
321 |
322 | #### See also
323 | [print()](#print)
324 |
325 | [command()](#command)
326 |
327 | [Back to interface](#interface)
328 |
329 |
330 |
331 | ## noDisplay()
332 | #### Description
333 | Turns the display off quickly. If the display does not have an option to turn on the display, the function just turns backlight on.
334 |
335 | #### Syntax
336 | void noDisplay();
337 |
338 | #### Alias
339 | void off();
340 |
341 | #### Parameters
342 | None
343 |
344 | #### Returns
345 | None
346 |
347 | #### See also
348 | [display()](#display)
349 |
350 | [Back to interface](#interface)
351 |
352 |
353 |
354 | ## display()
355 | #### Description
356 | Turns the display on quickly. If the display does not have an option to turn off the display, the function just turns backlight off.
357 |
358 | #### Syntax
359 | void display();
360 |
361 | #### Alias
362 | void on();
363 |
364 | #### Parameters
365 | None
366 |
367 | #### Returns
368 | None
369 |
370 | #### See also
371 | [noDisplay()](#noDisplay)
372 |
373 | [Back to interface](#interface)
374 |
375 |
376 |
377 | ## scrollDisplayLeft()
378 | #### Description
379 | Scrolls the display text to the left without changing the RAM. The function scrolls entire 40 character buffer. If you print 40 characters to a row and start scrolling, you get continuous moving banner in a row especially on 1602 LCDs.
380 |
381 | #### Syntax
382 | void scrollDisplayLeft();
383 |
384 | #### Parameters
385 | None
386 |
387 | #### Returns
388 | None
389 |
390 | #### See also
391 | [scrollDisplayRight()](#scrollDisplayRight)
392 |
393 | [Back to interface](#interface)
394 |
395 |
396 |
397 | ## scrollDisplayRight()
398 | #### Description
399 | Scrolls the display text to the right without changing the RAM. The function scrolls entire 40 character buffer. If you print 40 characters to a row and start scrolling, you get continuous moving banner in a row especially on 1602 LCDs.
400 |
401 | #### Syntax
402 | void scrollDisplayRight();
403 |
404 | #### Parameters
405 | None
406 |
407 | #### Returns
408 | None
409 |
410 | #### See also
411 | [scrollDisplayLeft()](#scrollDisplayLeft)
412 |
413 | [Back to interface](#interface)
414 |
415 |
416 |
417 | ## leftToRight()
418 | #### Description
419 | Sets the flow of text from left to right as it is normal for Latin languages.
420 |
421 | #### Syntax
422 | void leftToRight();
423 |
424 | #### Parameters
425 | None
426 |
427 | #### Returns
428 | None
429 |
430 | #### See also
431 | [rightToLeft()](#rightToLeft)
432 |
433 | [Back to interface](#interface)
434 |
435 |
436 |
437 | ## rightToLeft()
438 | #### Description
439 | Sets the flow of text from right to left as it is normal for Arabic languages.
440 |
441 | #### Syntax
442 | void rightToLeft();
443 |
444 | #### Parameters
445 | None
446 |
447 | #### Returns
448 | None
449 |
450 | #### See also
451 | [leftToRight()](#leftToRight)
452 |
453 | [Back to interface](#interface)
454 |
455 |
456 |
457 | ## noAutoscroll()
458 | #### Description
459 | Justifies the text from the cursor to the left.
460 |
461 | #### Syntax
462 | void noAutoscroll();
463 |
464 | #### Parameters
465 | None
466 |
467 | #### Returns
468 | None
469 |
470 | #### See also
471 | [autoscroll()](#autoscroll)
472 |
473 | [Back to interface](#interface)
474 |
475 |
476 |
477 | ## autoscroll()
478 | #### Description
479 | Justifies the text from the cursor to the right.
480 |
481 | #### Syntax
482 | void autoscroll();
483 |
484 | #### Parameters
485 | None
486 |
487 | #### Returns
488 | None
489 |
490 | #### See also
491 | [noAutoscroll()](#noAutoscroll)
492 |
493 | [Back to interface](#interface)
494 |
495 |
496 |
497 | ## noBacklight()
498 | #### Description
499 | Turns the backlight off.
500 |
501 | #### Syntax
502 | void noBacklight();
503 |
504 | #### Alias
505 | void setBacklight(0);
506 |
507 | #### Parameters
508 | None
509 |
510 | #### Returns
511 | None
512 |
513 | #### See also
514 | [backlight()](#backlight)
515 |
516 | [Back to interface](#interface)
517 |
518 |
519 |
520 | ## backlight()
521 | #### Description
522 | Turns the backlight on.
523 |
524 | #### Syntax
525 | void backlight();
526 |
527 | #### Alias
528 | void setBacklight(1);
529 |
530 | #### Parameters
531 | None
532 |
533 | #### Returns
534 | None
535 |
536 | #### See also
537 | [noBacklight()](#noBacklight)
538 |
539 | [Back to interface](#interface)
540 |
541 |
542 |
543 | ## noCursor()
544 | #### Description
545 | Turns the block cursor off.
546 |
547 | #### Syntax
548 | void noCursor();
549 |
550 | #### Alias
551 | void cursor_off();
552 |
553 | #### Parameters
554 | None
555 |
556 | #### Returns
557 | None
558 |
559 | #### See also
560 | [cursor()](#cursor)
561 |
562 | [Back to interface](#interface)
563 |
564 |
565 |
566 | ## cursor()
567 | #### Description
568 | Turns the block cursor on.
569 |
570 | #### Syntax
571 | void cursor();
572 |
573 | #### Alias
574 | void cursor_on();
575 |
576 | #### Parameters
577 | None
578 |
579 | #### Returns
580 | None
581 |
582 | #### See also
583 | [noCursor()](#noCursor)
584 |
585 | [Back to interface](#interface)
586 |
587 |
588 |
589 | ## noBlink()
590 | #### Description
591 | Turns on the blinking underline cursor.
592 |
593 | #### Syntax
594 | void noBlink();
595 |
596 | #### Alias
597 | void blink_off();
598 |
599 | #### Parameters
600 | None
601 |
602 | #### Returns
603 | None
604 |
605 | #### See also
606 | [blink()](#blink)
607 |
608 | [Back to interface](#interface)
609 |
610 |
611 |
612 | ## blink()
613 | #### Description
614 | Turns off the blinking underline cursor.
615 |
616 | #### Syntax
617 | void blink();
618 |
619 | #### Alias
620 | void blink_on();
621 |
622 | #### Parameters
623 | None
624 |
625 | #### Returns
626 | None
627 |
628 | #### See also
629 | [noBlink()](#noBlink)
630 |
631 | [Back to interface](#interface)
632 |
633 |
634 |
635 | ## setCursor()
636 | #### Description
637 | Fills the first 8 character generator RAM (CGRAM) locations with custom characters.
638 |
639 | #### Syntax
640 | void setCursor(uint8_t col, uint8_t row);
641 |
642 | #### Parameters
643 | - **col**: Number of a column where the cursor will be located counting from 0.
644 | - *Valid values*: unsigned byte 0 to [cols - 1](#prm_cols) of the [constructor](#LiquidCrystal_I2C)
645 | - *Default value*: none
646 |
647 |
648 | - **row**: Number of a row where the cursor will be located counting from 0.
649 | - *Valid values*: unsigned byte 0 to [rows - 1](#prm_rows) of the [constructor](#LiquidCrystal_I2C)
650 | - *Default value*: none
651 |
652 | #### Returns
653 | None
654 |
655 | #### See also
656 | [home()](#home)
657 |
658 | [Back to interface](#interface)
659 |
660 |
661 |
662 | ## init_bargraph()
663 | #### Description
664 | Initializes particular bar graph. The function creates a set of custom
665 | characters for displaying bar graphs. Some number of first current custom
666 | characters (5 or 8) will be overwritten according to the type of graph.
667 |
668 | #### Syntax
669 | uint8_t init_bargraph(uint8_t graphtype);
670 |
671 | #### Parameters
672 | - **graphtype**: Type of a graph.
673 | - *Valid values*: unsigned integer
674 | - LCDI2C_VERTICAL_BAR_GRAPH - rewrites all 8 custom characters
675 | - LCDI2C_HORIZONTAL_BAR_GRAPH - rewrites first 5 custom characters
676 | - LCDI2C_HORIZONTAL_LINE_GRAPH - rewrites first 5 custom characters
677 | - *Default value*: none
678 |
679 | #### Returns
680 | - **ResultCode**: Numeric code determining processing of the initialization.
681 | - 0: success
682 | - 1: failure, e.g., not recognized graph type
683 |
684 | #### See also
685 | [draw_horizontal_graph()](#draw_horizontal_graph)
686 |
687 | [draw_vertical_graph()](#draw_vertical_graph)
688 |
689 | [Back to interface](#interface)
690 |
691 |
692 |
693 | ## draw_horizontal_graph()
694 | #### Description
695 | Displays horizontal graph from desired cursor position with input value.
696 | - The bar graph is composed of solid, full rectangle characters eventually except final character with reduced vertical pipes. Value of the bar graph is displayed as equivalent number of pipes in the graph segment.
697 | - The line graph is composed of one pipe running across a LCD row. Value
698 | of the bar graph is displayed as a pipe at equivalent dot position in the graph segment.
699 | - The function is overloaded by data type of a displayed graph value, which
700 | determines its form.
701 | - Zero value of the graph is displayed as the very left pipe in the graph segment due to counting from 0, so that the graph always displays something.
702 |
703 | #### Syntax
704 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end);
705 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint16_t percentage);
706 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, float ratio);
707 |
708 | #### Parameters
709 | - **row**: Row positon of graph segment counting from 0 to physical number of rows.
710 | - *Valid values*: non-negative integer 0 to [rows - 1](#prm_rows) of the [constructor](#LiquidCrystal_I2C)
711 | - *Default value*: none
712 |
713 |
714 | - **col**: Column position of graph segment counting from 0 physical number of columns on a row.
715 | - *Valid values*: non-negative integer 0 to [cols - 1](#prm_cols) of the [constructor](#LiquidCrystal_I2C)
716 | - *Default value*: none
717 |
718 |
719 | - **len**: Length of a graph segment in characters limited to remaining physical columns from starting *col* position.
720 | - *Valid values*: non-negative integer 0 to [cols - col](#prm_cols) of the [constructor](#LiquidCrystal_I2C)
721 | - *Default value*: none
722 |
723 |
724 | - **pixel_col_end**: Displayed value in pipes (horizontal dots) counting from 0 to number of pipes of the graph segment. A sketch should calculate the number of segment pipes in order to map an application value to displayed value.
725 | - *Valid values*: non-negative integer 0 to 5 * *len*
726 | - *Default value*: none
727 |
728 |
729 | - **percentage**: Displayed value in percentage of a graph segment length. Accepted value is rounded to integer per cents.
730 | - *Valid values*: non-negative integer 0 to 100
731 | - *Default value*: none
732 |
733 |
734 | - **ratio**: Displayed value as a fragment of a graph segment length.
735 | - *Valid values*: non-negative decimal 0. to 1.
736 | - *Default value*: none
737 |
738 | #### Returns
739 | None
740 |
741 | #### See also
742 | [init_bargraph()](#init_bargraph)
743 |
744 | [draw_vertical_graph()](#draw_vertical_graph)
745 |
746 | [Back to interface](#interface)
747 |
748 |
749 |
750 | ## draw_vertical_graph()
751 | #### Description
752 | Displays vertical bar from desired cursor position with input value.
753 | - The bar graph is composed of solid, full rectangle characters eventually except final character with reduced horizontal dashes. Value of the bar graph is displayed as equivalent number of dashes in the graph segment.
754 | - The function is overloaded by data type of a displayed graph value, which
755 | determines its form.
756 |
757 | #### Syntax
758 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end);
759 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint16_t percentage);
760 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, float ratio);
761 |
762 | #### Parameters
763 | - **row**: Row positon of graph segment counting from 0 to physical limit.
764 | - *Valid values*: non-negative integer 0 to [rows - 1](#prm_rows) of the [constructor](#LiquidCrystal_I2C)
765 | - *Default value*: none
766 |
767 |
768 | - **col**: Column position of graph segment counting from 0 physical limit.
769 | - *Valid values*: non-negative integer 0 to [cols - 1](#prm_cols) of the [constructor](#LiquidCrystal_I2C)
770 | - *Default value*: none
771 |
772 |
773 | - **len**: Length of a graph segment in rows limited to remaining physical rows from starting *row* position.
774 | - *Valid values*: non-negative integer 0 to [row + 1](#prm_rows) of the [constructor](#LiquidCrystal_I2C)
775 | - *Default value*: none
776 |
777 |
778 | - **pixel_col_end**: Displayed value in dashes (vertical dots) counting from 0 to number of dashes of the graph segment. A sketch should calculate the number of segment dashes in order to map an application value to displayed value.
779 | - *Valid values*: non-negative integer 0 to 8 * *len* or 10 * *len*
780 | - *Default value*: none
781 |
782 |
783 | - **percentage**: Displayed value in percentage of a graph segment length. Accepted value is rounded to integer per cents.
784 | - *Valid values*: non-negative integer 0 to 100
785 | - *Default value*: none
786 |
787 |
788 | - **ratio**: Displayed value as a fragment of a graph segment length.
789 | - *Valid values*: non-negative decimal 0. to 1.
790 | - *Default value*: none
791 |
792 | #### Returns
793 | None
794 |
795 | #### See also
796 | [init_bargraph()](#init_bargraph)
797 |
798 | [draw_horizontal_graph()](#draw_horizontal_graph)
799 |
800 | [Back to interface](#interface)
801 |
802 |
803 |
804 | ## createChar()
805 | #### Description
806 | Fills the first 8 character generator RAM (CGRAM) locations with custom characters.
807 |
808 | #### Syntax
809 | void createChar(uint8_t, uint8_t[]);
810 |
811 | #### Alias
812 | void load_custom_character(uint8_t char_num, uint8_t *rows);
813 |
814 | #### Parameters
815 | - **char_num**: Position of a custom character in CGRAM for custom chars.
816 | - *Valid values*: 0 - 7
817 | - *Default value*: none
818 |
819 |
820 | - **uint8_t[]**: Array of custom characters definitions.
821 | - *Valid values*: Character row byte patterns from the top of the char.
822 | - Array length 8 bytes for 5x8 characters.
823 | - Array length 10 bytes for 5x10 characters.
824 | - *Default value*: none
825 |
826 |
827 | - **rows**: Pointer to the array of custom characters definitions.
828 |
829 | #### Returns
830 | None
831 |
832 | #### See also
833 | [init_bargraph()](#init_bargraph)
834 |
835 | [Back to interface](#interface)
836 |
837 |
838 |
839 | ## command()
840 | #### Description
841 | Sends a command to the display. It is useful for commands not supported
842 | by the library.
843 |
844 | #### Syntax
845 | void command(uint8_t value);
846 |
847 | #### Parameters
848 | - **value**: Command code that should be send to the LCD.
849 | - *Valid values*: unsigned byte
850 | - *Default value*: none
851 |
852 | #### Returns
853 | None
854 |
855 | #### See also
856 | [write()](#write)
857 |
858 | [Back to interface](#interface)
859 |
--------------------------------------------------------------------------------
/examples/Autoscroll/Autoscroll.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demonstration of Autoscroll function
4 |
5 | DESCRIPTION:
6 | This sketch demonstrates the use of the autoscroll() and noAutoscroll()
7 | functions to make new text scroll or not.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * The sketch is just for demonstration purposes, so that it is not
11 | optimized for memory usage.
12 |
13 | LICENSE:
14 | This program is free software; you can redistribute it and/or modify
15 | it under the terms of the MIT License (MIT).
16 |
17 | CREDENTIALS:
18 | Author: Libor Gabaj
19 | Version: 1.0.0
20 | Updated: 20.03.2016
21 |
22 | CREDIT:
23 | The example taken and rewritten for I2C from official Arduino standard library
24 | (https://github.com/arduino/Arduino/tree/master/libraries/LiquidCrystal)
25 | */
26 | #include
27 | #include
28 |
29 | // LCD address and geometry and library initialization
30 | const byte lcdAddr = 0x27; // Address of I2C backpack
31 | const byte lcdCols = 16; // Number of character in a row
32 | const byte lcdRows = 2; // Number of lines
33 | //const byte lcdAddr = 0x3F; // Address of I2C backpack
34 | //const byte lcdCols = 20; // Number of character in a row
35 | //const byte lcdRows = 4; // Number of lines
36 |
37 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
38 |
39 | // Demo parameters
40 | const byte lcdScrollRow = 0; // Number of a demo row counting from 0
41 | const unsigned int digitDelay = 500; // Miliseconds before displaying next digit
42 |
43 | // Function for displaying demo digits
44 | void printDigits() {
45 | for (byte thisChar = 0; thisChar < 10; thisChar++) {
46 | lcd.print(thisChar);
47 | delay(digitDelay);
48 | }
49 | }
50 |
51 | void setup() {
52 | lcd.init();
53 | lcd.backlight();
54 | }
55 |
56 | void loop() {
57 | lcd.setCursor(0, lcdScrollRow);
58 | printDigits();
59 |
60 | // Set the cursor to the last column of the demo row and turn on autoscroll
61 | lcd.setCursor(lcdCols, lcdScrollRow);
62 | lcd.autoscroll();
63 | printDigits();
64 | lcd.noAutoscroll();
65 | lcd.clear();
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/examples/CompleteTest/CompleteTest.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demo sketch for complete printing test of LCD
4 |
5 | DESCRIPTION:
6 | The sketch demonstrates capabalities of the LCD by displaying several
7 | test.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * The sketch is just for demonstration purposes, so that it is not
11 | optimized for memory usage.
12 |
13 | LICENSE:
14 | This program is free software; you can redistribute it and/or modify
15 | it under the terms of the MIT License (MIT).
16 |
17 | CREDITS:
18 | Inspired by the example LCD_Test in the library LCDi2cW
19 | from "4-2-2009 dale@wentztech.com".
20 |
21 | CREDENTIALS:
22 | Author: Libor Gabaj
23 | Version: 1.1.0
24 | Updated: 04.03.2015
25 | */
26 | #include
27 | #include
28 |
29 | // LCD address and geometry for LCD 1602
30 | const byte lcdAddr = 0x27; // Typical address of I2C backpack for 1602
31 | const byte lcdCols = 16; // Number of characters in a row of display
32 | const byte lcdRows = 2; // Number of lines of display
33 |
34 | // LCD address and geometry for LCD 2004
35 | //const byte lcdAddr = 0x3F; // Typical address of I2C backpack for 2004
36 | //const byte lcdCols = 20; // Number of characters in a row of display
37 | //const byte lcdRows = 4; // Number of lines of display
38 |
39 | // Initialize library and setting LCD geometry
40 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
41 |
42 | // Demo constants
43 | const int testDelay = 500; // Delay between tests in ms
44 | const int demoDelay = 3000; // Delay between demos in ms
45 | const byte demoNumMin = 1; // Range of demo tests
46 | const byte demoNumMax = 255;
47 | const byte charNumMin = 0; // Code of first displayed character
48 | const byte charNumMax = 255; // Code of last displayed character
49 |
50 | // Demo variables
51 | byte col, row;
52 | unsigned int demoNum, charNum;
53 | char buffer[lcdCols + 1];
54 |
55 | void setup() {
56 | // Initialize LCD
57 | lcd.init();
58 | lcd.backlight(); // Switch on the backlight LED, if any or wired
59 | }
60 |
61 | void loop()
62 | {
63 | demoNum = max(demoNumMin, 1);
64 | while(demoNum >= demoNumMin && demoNum <= demoNumMax) {
65 | lcd.clear();
66 | lcd.cursor_off();
67 | lcd.blink_off();
68 | sprintf(buffer, "%u.", demoNum);
69 | lcd.print(buffer);
70 |
71 | switch (demoNum) {
72 | case 1:
73 | lcd.print(F("Hello World!"));
74 | break;
75 | case 2:
76 | lcd.print(F("Dash Cursor"));
77 | lcd.setCursor(0, 1);
78 | lcd.cursor_on();
79 | break;
80 | case 3:
81 | lcd.print (F("Block Cursor"));
82 | lcd.setCursor(0, 1);
83 | lcd.blink_on();
84 | break;
85 | case 4:
86 | lcd.print(F("No Cursor"));
87 | lcd.setCursor(0, 1);
88 | break;
89 | case 5:
90 | lcd.print(F("Characters"));
91 | lcd.cursor_on();
92 | charNum = charNumMin;
93 | while(charNum <= charNumMax) {
94 | row = 1;
95 | do {
96 | lcd.clear(row);
97 | col = 0;
98 | lcd.setCursor(col, row);
99 | do {
100 | lcd.write(char(charNum++));
101 | delay(testDelay);
102 | } while(++col < lcdCols && charNum <= charNumMax);
103 | } while(++row < lcdRows && charNum <= charNumMax);
104 | }
105 | lcd.cursor_off();
106 | break;
107 | case 6:
108 | for (byte row=0; row < lcdRows; row++) {
109 | lcd.print(F("Line "));
110 | lcd.print(row);
111 | delay(testDelay);
112 | lcd.setCursor(0, row + 1);
113 | }
114 | break;
115 | case 7:
116 | lcd.print(F("Count to 255"));
117 | for (unsigned int i = 0; i < 256; i++) {
118 | lcd.clear(1);
119 | sprintf(buffer, "%03u 0x%02X %c", i, i, i);
120 | lcd.print(buffer);
121 | if (lcdCols >= 20) {
122 | lcd.print(" B");
123 | lcd.print(i, BIN);
124 | }
125 | delay(testDelay);
126 | }
127 | break;
128 | case 8:
129 | lcd.print(F("Positions"));
130 | lcd.setCursor(0, 1);
131 | for (byte col = 0; col < lcdCols; col++) {
132 | lcd.write(col%10 + char('0'));
133 | delay(testDelay);
134 | }
135 | break;
136 | case 9:
137 | lcd.print(F("Clearing"));
138 | for (byte row = 1; row < lcdRows; row++) {
139 | // Fill row
140 | lcd.setCursor(0, row);
141 | for (byte col = 0; col < lcdCols; col++) {
142 | lcd.write(col%10 + char('0'));
143 | }
144 | delay(testDelay);
145 | // Clear row
146 | for (byte i = 0; i < lcdCols / 2; i++) {
147 | lcd.setCursor(lcdCols / 2 - i - 1, row);
148 | lcd.write(' ');
149 | lcd.setCursor(lcdCols / 2 + i, row);
150 | lcd.write(' ');
151 | delay(testDelay);
152 | }
153 | }
154 | break;
155 | default:
156 | demoNum = 0;
157 | continue;
158 | }
159 | delay(demoDelay);
160 | demoNum++;
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/examples/CustomChars/CustomChars.ino:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | uint8_t bell[8] = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
5 | uint8_t note[8] = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
6 | uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
7 | uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
8 | uint8_t duck[8] = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
9 | uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
10 | uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
11 | uint8_t retarrow[8] = { 0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
12 |
13 | LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
14 |
15 | void setup()
16 | {
17 | lcd.init(); // initialize the lcd
18 | lcd.backlight();
19 |
20 | lcd.createChar(0, bell);
21 | lcd.createChar(1, note);
22 | lcd.createChar(2, clock);
23 | lcd.createChar(3, heart);
24 | lcd.createChar(4, duck);
25 | lcd.createChar(5, check);
26 | lcd.createChar(6, cross);
27 | lcd.createChar(7, retarrow);
28 | lcd.home();
29 |
30 | lcd.print("Hello world...");
31 | lcd.setCursor(0, 1);
32 | lcd.print(" i ");
33 | lcd.write(3);
34 | lcd.print(" arduinos!");
35 | delay(5000);
36 | displayKeyCodes();
37 |
38 | }
39 |
40 | // display all keycodes
41 | void displayKeyCodes(void) {
42 | uint8_t i = 0;
43 | while (1) {
44 | lcd.clear();
45 | lcd.print("Codes 0x"); lcd.print(i, HEX);
46 | lcd.print("-0x"); lcd.print(i+16, HEX);
47 | lcd.setCursor(0, 1);
48 | for (int j=0; j<16; j++) {
49 | lcd.write(i+j);
50 | }
51 | i+=16;
52 |
53 | delay(4000);
54 | }
55 | }
56 |
57 | void loop()
58 | {
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/examples/HelloWorld/HelloWorld.ino:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
5 |
6 | void setup()
7 | {
8 | lcd.init(); // initialize the lcd
9 |
10 | // Print a message to the LCD.
11 | lcd.backlight();
12 | lcd.print("Hello, world!");
13 | }
14 |
15 | void loop()
16 | {
17 | }
18 |
--------------------------------------------------------------------------------
/examples/Histogram/Histogram.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demo sketch for Histogram composed of Vertical Bar Graphs
4 |
5 | DESCRIPTION:
6 | The sketch demonstrates usage of LiquidCrystal_I2C library version 2.x
7 | for programing histograms with help of vertical graphs.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * All graph values are displayed in number of vertical pixels.
11 | * The sketch demostrates a histogram
12 | - in second row with one row height
13 | - in full display are with
14 | with values changed randomly.
15 | * The sketch is just for demonstration purposes, so that it is not
16 | optimized for memory usage.
17 |
18 | LICENSE:
19 | This program is free software; you can redistribute it and/or modify
20 | it under the terms of the MIT License (MIT).
21 |
22 | CREDENTIALS:
23 | Author: Libor Gabaj
24 | Version: 1.0.0
25 | Updated: 01.03.2015
26 | */
27 |
28 | /* Needed libraries
29 | Dispite the LCD library includes Wire library, the ArduinoIDE does not
30 | includes nested libraries, if they are not in the same folder.
31 | */
32 | #include
33 | #include
34 |
35 | // LCD address and geometry for LCD 1602
36 | const byte lcdAddr = 0x27; // Typical address of I2C backpack for 1602
37 | const byte lcdCols = 16; // Number of characters in a row of display
38 | const byte lcdRows = 2; // Number of lines of display
39 |
40 | // LCD address and geometry for LCD 2004
41 | //const byte lcdAddr = 0x3F; // Typical address of I2C backpack for 2004
42 | //const byte lcdCols = 20; // Number of characters in a row of display
43 | //const byte lcdRows = 4; // Number of lines of display
44 |
45 | // Initialize library and setting LCD geometry
46 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
47 |
48 | // Demo constants
49 | const int graphDelay = 100; // Delay between histograms
50 | const int demoTime = 5000; // Showing time of a demo
51 |
52 | // Demo variables
53 | byte graphPixelsCur, graphPixelsMax;
54 | unsigned long demoStart;
55 |
56 | void setup()
57 | {
58 | // Initialize LCD
59 | lcd.init();
60 | lcd.backlight(); // Switch on the backlight LED, if any or wired
61 |
62 | /* Initialize graph
63 | * Macro is defined in LiquidCrystal_I2C library.
64 | * Function uses all 8 custom character positions (0-7)
65 | and creates custom characters for displaying vertical bar.
66 | */
67 | lcd.init_bargraph(LCDI2C_VERTICAL_BAR_GRAPH);
68 | }
69 |
70 | void loop()
71 | {
72 | // Demo 1: One row histogram
73 | lcd.clear();
74 | lcd.print("Histogram");
75 | graphPixelsMax = LCD_CHARACTER_VERTICAL_DOTS;
76 | demoStart = millis();
77 | while(millis() - demoStart < demoTime) {
78 | for(byte graphCol = 0; graphCol < lcdCols; graphCol++) {
79 | graphPixelsCur = random(0, graphPixelsMax);
80 | lcd.draw_vertical_graph(1, graphCol, 1, graphPixelsCur);
81 | }
82 | delay(graphDelay);
83 | }
84 | // Demo 2: Full display histogram
85 | lcd.clear();
86 | graphPixelsMax = lcdRows * LCD_CHARACTER_VERTICAL_DOTS;
87 | demoStart = millis();
88 | while(millis() - demoStart < demoTime) {
89 | for(byte graphCol = 0; graphCol < lcdCols; graphCol++) {
90 | graphPixelsCur = random(0, graphPixelsMax);
91 | lcd.draw_vertical_graph(lcdRows - 1, graphCol, lcdRows, graphPixelsCur);
92 | }
93 | delay(graphDelay);
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/examples/HorizontalBarGraph/HorizontalBarGraph.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demo sketch for Horizontal Bar Graph
4 |
5 | DESCRIPTION:
6 | The sketch demonstrates usage of LiquidCrystal_I2C library version 2.x
7 | for programing horizontal graphs, which mimics progress bar.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * All graph values are displayed in number of horizontal pixels.
11 | * The sketch demostrates
12 | - 1. Continues full row progress bar
13 | - 2. Continues half row central progress bar
14 | - 3. Random full row progress bar
15 | * The sketch is just for demonstration purposes, so that it is not
16 | optimized for memory usage.
17 |
18 | LICENSE:
19 | This program is free software; you can redistribute it and/or modify
20 | it under the terms of the MIT License (MIT).
21 |
22 | CREDENTIALS:
23 | Author: Libor Gabaj
24 | Version: 1.0.0
25 | Updated: 01.03.2015
26 | */
27 |
28 | /* Needed libraries
29 | Dispite the LCD library includes Wire library, the ArduinoIDE does not
30 | includes nested libraries, if they are not in the same folder.
31 | */
32 | #include
33 | #include
34 |
35 | // LCD address and geometry for LCD 1602
36 | const byte lcdAddr = 0x27; // Typical address of I2C backpack for 1602
37 | const byte lcdCols = 16; // Number of characters in a row of display
38 | const byte lcdRows = 2; // Number of lines of display
39 |
40 | // LCD address and geometry for LCD 2004
41 | //const byte lcdAddr = 0x3F; // Typical address of I2C backpack for 2004
42 | //const byte lcdCols = 20; // Number of characters in a row of display
43 | //const byte lcdRows = 4; // Number of lines of display
44 |
45 | // Initialize library and setting LCD geometry
46 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
47 |
48 | // Cursor coordinates and character row pattern for progress bar
49 | const byte graphRow = 1; // In this row the graph is displayed
50 | const byte labelRow = 0; // In this row the label is displayed
51 | const byte valueCol = lcdCols - 2; // In this column starts graph value
52 | const int graphDelay = 100; // Delay between graph values in ms
53 | const int demoDelay = 3000; // Delay between demos in ms
54 |
55 | // Demo parameters
56 | const char graphType[] = " Bar";
57 | const char* graphLbls[] = {"Full", "Half", "Random"};
58 | const byte graphLens[] = {lcdCols, lcdCols / 2, lcdCols};
59 | const byte graphCols[] = {0, lcdCols / 4, 0};
60 |
61 | // Demo variables
62 | byte graphPixelsCur, graphPixelsMax;
63 |
64 | // Function for displaying graph label
65 | void printLabel(byte demo) {
66 | // Create label
67 | char labelText[valueCol];
68 | sprintf(labelText, "%1u.%s%s", demo + 1, graphLbls[demo], graphType);
69 | // Display label on clear display
70 | lcd.clear();
71 | lcd.setCursor(0, labelRow);
72 | lcd.print(labelText);
73 |
74 | }
75 |
76 | // Function for displaying graph value
77 | void printValue(byte value) {
78 | lcd.clear(labelRow, valueCol); // Clear value space
79 | lcd.setCursor(valueCol, labelRow);
80 | lcd.print(value);
81 | }
82 |
83 | void setup()
84 | {
85 | // Initialize LCD
86 | lcd.init();
87 | lcd.backlight(); // Switch on the backlight LED, if any or wired
88 |
89 | /* Initialize graph
90 | * Macro is defined in LiquidCrystal_I2C library.
91 | * Function uses the first 5 custom character positions (0-4)
92 | and creates custom characters for displaying progress bar.
93 | */
94 | lcd.init_bargraph(LCDI2C_HORIZONTAL_BAR_GRAPH);
95 | }
96 |
97 | void loop()
98 | {
99 | for(byte demoNum = 0; demoNum < sizeof(graphLens)/sizeof(graphLens[0]); demoNum++) {
100 | graphPixelsMax = graphLens[demoNum] * LCD_CHARACTER_HORIZONTAL_DOTS;
101 | printLabel(demoNum);
102 | switch (demoNum) {
103 | case 0:
104 | case 1:
105 | // Demo 1: Graph in full row with sequence values
106 | // Demo 2: Graph in half row with sequence values
107 | // Descending graph values
108 | for (byte i = graphPixelsMax; i > 0; i--) {
109 | graphPixelsCur = i - 1;
110 | printValue(graphPixelsCur);
111 | lcd.draw_horizontal_graph(graphRow, graphCols[demoNum], graphLens[demoNum], graphPixelsCur);
112 | delay(graphDelay);
113 | }
114 | // Ascending graph values
115 | for (byte i = 0; i < graphPixelsMax; i++) {
116 | graphPixelsCur = i;
117 | printValue(graphPixelsCur);
118 | lcd.draw_horizontal_graph(graphRow, graphCols[demoNum], graphLens[demoNum], graphPixelsCur);
119 | delay(graphDelay);
120 | }
121 | break;
122 | case 2:
123 | // Demo 3: Graph in full row with random values
124 | for (byte i = 0; i < graphPixelsMax; i++) {
125 | graphPixelsCur = random(0, graphPixelsMax);
126 | printValue(graphPixelsCur);
127 | lcd.draw_horizontal_graph(graphRow, graphCols[demoNum], graphLens[demoNum], graphPixelsCur);
128 | delay(graphDelay);
129 | }
130 | break;
131 | }
132 | delay(demoDelay);
133 | }
134 | }
135 |
136 |
--------------------------------------------------------------------------------
/examples/HorizontalLineGraph/HorizontalLineGraph.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demo sketch for Horizontal Line Graph
4 |
5 | DESCRIPTION:
6 | The sketch demonstrates usage of LiquidCrystal_I2C library version 2.x
7 | for programing horizontal graphs, which mimics scale graphs.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * All graph values are displayed in number of horizontal pixels.
11 | * The sketch demostrates
12 | - 1. Continues full row scale graph
13 | - 2. Continues half row central scale graph
14 | - 3. Random full row scale graph
15 | * The sketch is just for demonstration purposes, so that it is not
16 | optimized for memory usage.
17 |
18 | LICENSE:
19 | This program is free software; you can redistribute it and/or modify
20 | it under the terms of the MIT License (MIT).
21 |
22 | CREDENTIALS:
23 | Author: Libor Gabaj
24 | Version: 1.0.0
25 | Updated: 01.03.2015
26 | */
27 |
28 | /* Needed libraries
29 | Dispite the LCD library includes Wire library, the ArduinoIDE does not
30 | includes nested libraries, if they are not in the same folder.
31 | */
32 | #include
33 | #include
34 |
35 | // LCD address and geometry for LCD 1602
36 | const byte lcdAddr = 0x27; // Typical address of I2C backpack for 1602
37 | const byte lcdCols = 16; // Number of characters in a row of display
38 | const byte lcdRows = 2; // Number of lines of display
39 |
40 | // LCD address and geometry for LCD 2004
41 | //const byte lcdAddr = 0x3F; // Typical address of I2C backpack for 2004
42 | //const byte lcdCols = 20; // Number of characters in a row of display
43 | //const byte lcdRows = 4; // Number of lines of display
44 |
45 | // Initialize library and setting LCD geometry
46 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
47 |
48 | // Cursor coordinates and character row pattern for progress bar
49 | const byte graphRow = 1; // In this row the graph is displayed
50 | const byte labelRow = 0; // In this row the label is displayed
51 | const byte valueCol = lcdCols - 2; // In this column starts graph value
52 | const int graphDelay = 200; // Delay between graph values in ms
53 | const int demoDelay = 3000; // Delay between demos in ms
54 |
55 | // Demo parameters
56 | const char graphType[] = "Scale";
57 | const char* graphLbls[] = {"Full ", "Half ", "Random"};
58 | const byte graphLens[] = {lcdCols, lcdCols / 2, lcdCols};
59 | const byte graphCols[] = {0, lcdCols / 4, 0};
60 |
61 | // Demo variables
62 | byte graphPixelsCur, graphPixelsMax;
63 |
64 | // Function for displaying graph label
65 | void printLabel(byte demo) {
66 | // Create label
67 | char labelText[valueCol];
68 | sprintf(labelText, "%1u.%s%s", demo + 1, graphLbls[demo], graphType);
69 | // Display label on clear display
70 | lcd.clear();
71 | lcd.setCursor(0, labelRow);
72 | lcd.print(labelText);
73 |
74 | }
75 |
76 | // Function for displaying graph value
77 | void printValue(byte value) {
78 | lcd.clear(labelRow, valueCol); // Clear value space
79 | lcd.setCursor(valueCol, labelRow);
80 | lcd.print(value);
81 | }
82 |
83 | void setup()
84 | {
85 | // Initialize LCD
86 | lcd.init();
87 | lcd.backlight(); // Switch on the backlight LED, if any or wired
88 |
89 | /* Initialize graph
90 | * Macro is defined in LiquidCrystal_I2C library.
91 | * Function uses the first 5 custom character positions (0-4)
92 | and creates custom characters for displaying progress bar.
93 | */
94 | lcd.init_bargraph(LCDI2C_HORIZONTAL_LINE_GRAPH);
95 | }
96 |
97 | void loop()
98 | {
99 | for(byte demoNum = 0; demoNum < sizeof(graphLens)/sizeof(graphLens[0]); demoNum++) {
100 | graphPixelsMax = graphLens[demoNum] * LCD_CHARACTER_HORIZONTAL_DOTS;
101 | printLabel(demoNum);
102 | switch (demoNum) {
103 | case 0:
104 | case 1:
105 | // Demo 1: Graph in full row with sequence values
106 | // Demo 2: Graph in half row with sequence values
107 | // Descending graph values
108 | for (byte i = graphPixelsMax; i > 0; i--) {
109 | graphPixelsCur = i - 1;
110 | printValue(graphPixelsCur);
111 | lcd.draw_horizontal_graph(graphRow, graphCols[demoNum], graphLens[demoNum], graphPixelsCur);
112 | delay(graphDelay);
113 | }
114 | // Ascending graph values
115 | for (byte i = 0; i < graphPixelsMax; i++) {
116 | graphPixelsCur = i;
117 | printValue(graphPixelsCur);
118 | lcd.draw_horizontal_graph(graphRow, graphCols[demoNum], graphLens[demoNum], graphPixelsCur);
119 | delay(graphDelay);
120 | }
121 | break;
122 | case 2:
123 | // Demo 3: Graph in full row with random values
124 | for (byte i = 0; i < graphPixelsMax; i++) {
125 | graphPixelsCur = random(0, graphPixelsMax);
126 | printValue(graphPixelsCur);
127 | lcd.draw_horizontal_graph(graphRow, graphCols[demoNum], graphLens[demoNum], graphPixelsCur);
128 | delay(graphDelay);
129 | }
130 | break;
131 | }
132 | delay(demoDelay);
133 | }
134 | }
135 |
136 |
--------------------------------------------------------------------------------
/examples/MultipleLcd/MultipleLcd.ino:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | LiquidCrystal_I2C lcd1(0x26,16,2); // set the LCD address of the first lcd to 0x26 for a 16 chars and 2 line display
5 | LiquidCrystal_I2C lcd2(0x27,16,2); // set the LCD address of the second lcd to 0x27 for a 16 chars and 2 line display
6 |
7 | void setup()
8 | {
9 | lcd1.init(); // initialize the first lcd
10 | lcd2.init(); // initialize the second lcd
11 |
12 | // Print a message on the first LCD.
13 | lcd1.backlight();
14 | lcd1.print("Hello, #1 world!");
15 |
16 | // Print a message on the second LCD.
17 | lcd2.backlight();
18 | lcd2.print("Hello, #2 world!");
19 |
20 | }
21 |
22 | void loop()
23 | {
24 | }
25 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 |
2 | # LiquidCrystal_I2C
3 | It is the reimplementation of the standard Arduino LCD library, configured to work with parallel HD44780 compatible LCDs, and interfaced via a Chinese PCF8574 I2C serial extender.
4 |
5 |
6 | ## Examples
7 | ##### Autoscroll
8 | Demonstrates autoscroll function.
9 |
10 | ##### CompleteTest
11 | Demo sketch for complete printing test of the LCD. The test suit consist of 9 tests each labeled in the first row.
12 |
13 | ##### CustomChars
14 | Creation of 8 custom characters in form of graphical symbols.
15 |
16 | ##### HelloWorld
17 | Standard initial example. Use it for checking basic functionality and address of the LCD.
18 |
19 | ##### Histogram
20 | Demo sketch for several histograms composed of vertical bar graphs. The values for graphs are generated randomly.
21 | 1. The first demo histogram is displayed in one row only.
22 | 1. The second demo histogram display across all rows of the LCD and uses its entire screen.
23 |
24 | ##### HorizontalBarGraph
25 | Demo sketch for horizontal bar graphs.
26 | 1. The first demo histogram uses full row for continues increasing and decreasing values (breathing graph).
27 | 1. The second demo histogram is a breathing graph using just one half of a row.
28 | 1. The third demo histogram displays values generated randomly.
29 |
30 | ##### HorizontalLineGraph
31 | Demo sketch for horizontal line graphs. A value is represented just with a pipe on a row.
32 | 1. The first demo histogram uses full row for continues increasing and decreasing values (running graph).
33 | 1. The second demo histogram is a running graph using just one half of a row.
34 | 1. The third demo histogram displays values generated randomly.
35 |
36 | ##### MultipleLcd
37 | Using multiple LCD on the same I2C bus but communicating on different addresses.
38 |
39 | ##### Scroll
40 | Demonstrates scrolling text to the left and right without changing text.
41 |
42 | ##### SerialDisplay
43 | Sketch receives characters from the serial port and displays them on the LCD one by one.
44 |
45 | ##### VerticalBarGraph
46 | Demo sketch for vertical bar graph. The graph uses all rows in the last column for continues increasing and decreasing values (breathing graph).
--------------------------------------------------------------------------------
/examples/Scroll/Scroll.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demonstration scrolling text to the left and right without changing text.
4 |
5 | DESCRIPTION:
6 | This sketch demonstrates the use of the scrollDisplayLeft() and
7 | scrollDisplayRight() functions to make new text scroll to the left and right.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * The sketch is just for demonstration purposes, so that it is not
11 | optimized for memory usage.
12 |
13 | LICENSE:
14 | This program is free software; you can redistribute it and/or modify
15 | it under the terms of the MIT License (MIT).
16 |
17 | CREDENTIALS:
18 | Author: Libor Gabaj
19 | Version: 1.0.0
20 | Updated: 20.03.2016
21 |
22 | CREDIT:
23 | The example taken and rewritten for I2C from official Arduino standard library
24 | (https://github.com/arduino/Arduino/tree/master/libraries/LiquidCrystal)
25 | */
26 | #include
27 | #include
28 |
29 | // LCD address and geometry and library initialization
30 | const byte lcdAddr = 0x27; // Address of I2C backpack
31 | const byte lcdCols = 16; // Number of character in a row
32 | const byte lcdRows = 2; // Number of lines
33 | //const byte lcdAddr = 0x3F; // Address of I2C backpack
34 | //const byte lcdCols = 20; // Number of character in a row
35 | //const byte lcdRows = 4; // Number of lines
36 |
37 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
38 |
39 | // Demo parameters
40 | const char demoText[]= "Hello World!";
41 | const unsigned int scrollDelay = 500; // Miliseconds before scrolling next char
42 | const unsigned int demoDelay = 2000; // Miliseconds between demo loops
43 | byte textLen; // Number of visible characters in the text
44 |
45 | void setup() {
46 | textLen = sizeof(demoText) - 1;
47 | lcd.init();
48 | lcd.backlight();
49 | lcd.print(demoText);
50 | delay(demoDelay);
51 | }
52 |
53 | void loop() {
54 | // Scroll entire text in a row to the left outside the screen
55 | for (byte positionCounter = 0; positionCounter < textLen; positionCounter++) {
56 | lcd.scrollDisplayLeft();
57 | delay(scrollDelay);
58 | }
59 | // Scroll hidden text through entire row to the right outside the screen
60 | for (byte positionCounter = 0; positionCounter < textLen + lcdCols; positionCounter++) {
61 | lcd.scrollDisplayRight();
62 | delay(scrollDelay);
63 | }
64 | // Scroll text to the right back to original position
65 | for (byte positionCounter = 0; positionCounter < lcdCols; positionCounter++) {
66 | lcd.scrollDisplayLeft();
67 | delay(scrollDelay);
68 | }
69 | delay(demoDelay);
70 | }
71 |
72 |
--------------------------------------------------------------------------------
/examples/SerialDisplay/SerialDisplay.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Displays text sent over the serial port (e.g. from the Serial Monitor) on
3 | * an attached LCD.
4 | */
5 | #include
6 | #include
7 |
8 | LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
9 |
10 | void setup()
11 | {
12 | lcd.init(); // initialize the lcd
13 | lcd.backlight();
14 | Serial.begin(9600);
15 | }
16 |
17 | void loop()
18 | {
19 | // when characters arrive over the serial port...
20 | if (Serial.available()) {
21 | // wait a bit for the entire message to arrive
22 | delay(100);
23 | // clear the screen
24 | lcd.clear();
25 | // read all the available characters
26 | while (Serial.available() > 0) {
27 | // display each character to the LCD
28 | lcd.write(Serial.read());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/examples/VerticalBarGraph/VerticalBarGraph.ino:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | Demo sketch for Vertical Bar Graph
4 |
5 | DESCRIPTION:
6 | The sketch demonstrates usage of LiquidCrystal_I2C library version 2.x
7 | for programing vertical graphs, which mimics histogram.
8 | * The sketch is intended preferrably for 16x2 LCD, but can be configured
9 | for 20x4 LCDs just by uncommenting and commenting related sections.
10 | * All graph values are displayed in number of vertical pixels.
11 | * The sketch demostrates vertical graphs from one row graph to full rows
12 | graph of the display.
13 | * The sketch is just for demonstration purposes, so that it is not
14 | optimized for memory usage.
15 |
16 | LICENSE:
17 | This program is free software; you can redistribute it and/or modify
18 | it under the terms of the MIT License (MIT).
19 |
20 | CREDENTIALS:
21 | Author: Libor Gabaj
22 | Version: 1.0.0
23 | Updated: 01.03.2015
24 | */
25 |
26 | /* Needed libraries
27 | Dispite the LCD library includes Wire library, the ArduinoIDE does not
28 | includes nested libraries, if they are not in the same folder.
29 | */
30 | #include
31 | #include
32 |
33 | // LCD address and geometry for LCD 1602
34 | const byte lcdAddr = 0x27; // Typical address of I2C backpack for 1602
35 | const byte lcdCols = 16; // Number of characters in a row of display
36 | const byte lcdRows = 2; // Number of lines of display
37 |
38 | // LCD address and geometry for LCD 2004
39 | //const byte lcdAddr = 0x3F; // Typical address of I2C backpack for 2004
40 | //const byte lcdCols = 20; // Number of characters in a row of display
41 | //const byte lcdRows = 4; // Number of lines of display
42 |
43 | // Initialize library and setting LCD geometry
44 | LiquidCrystal_I2C lcd(lcdAddr, lcdCols, lcdRows);
45 |
46 | // Cursor coordinates and character row pattern for progress bar
47 | const byte graphCol = lcdCols - 1; // In this column the graph is displayed
48 | const int graphDelay = 200; // Delay between graph values in ms
49 | const int demoDelay = 3000; // Delay between demos in ms
50 |
51 | // Demo parameters
52 | const char graphType[] = " Col(s) Graph";
53 |
54 | // Demo variables
55 | byte graphPixelsCur, graphPixelsMax;
56 |
57 | // Function for displaying graph label
58 | void printLabel(byte rows) {
59 | const byte labelCol = 0;
60 | const byte labelRow = 0;
61 | // Create label
62 | char labelText[graphCol];
63 | sprintf(labelText, "%1u%s", rows, graphType);
64 | // Display label on clear display
65 | lcd.clear();
66 | lcd.setCursor(labelCol, labelRow);
67 | lcd.print(labelText);
68 |
69 | }
70 |
71 | // Function for displaying graph value
72 | void printValue(byte value) {
73 | const byte valueWidth = 2; // Max. digits in value
74 | const byte valueCol = graphCol - valueWidth - 1;
75 | const byte valueRow = 1;
76 | // Create value
77 | char valueFormat[4], valueText[valueWidth + 1];
78 | sprintf(valueFormat, "%%%1uu", valueWidth);
79 | sprintf(valueText, valueFormat, value);
80 | // Display label on clear display
81 | lcd.clear(valueRow, valueCol, valueWidth);
82 | lcd.setCursor(valueCol, valueRow);
83 | lcd.print(valueText);
84 | }
85 |
86 | void setup()
87 | {
88 | // Initialize LCD
89 | lcd.init();
90 | lcd.backlight(); // Switch on the backlight LED, if any or wired
91 |
92 | /* Initialize graph
93 | * Macro is defined in LiquidCrystal_I2C library.
94 | * Function uses all 8 custom character positions (0-7)
95 | and creates custom characters for displaying vertical bar.
96 | */
97 | lcd.init_bargraph(LCDI2C_VERTICAL_BAR_GRAPH);
98 | }
99 |
100 | void loop()
101 | {
102 | for(byte graphHight = 1; graphHight <= lcdRows; graphHight++) {
103 | graphPixelsMax = graphHight * LCD_CHARACTER_VERTICAL_DOTS;
104 | printLabel(graphHight);
105 | for (byte i = graphPixelsMax; i > 0; i--) {
106 | graphPixelsCur = i - 1;
107 | printValue(graphPixelsCur);
108 | lcd.draw_vertical_graph(graphHight - 1, graphCol, graphHight, graphPixelsCur);
109 | delay(graphDelay);
110 | }
111 | // Ascending graph values
112 | for (byte i = 0; i < graphPixelsMax; i++) {
113 | graphPixelsCur = i;
114 | printValue(graphPixelsCur);
115 | lcd.draw_vertical_graph(graphHight - 1, graphCol, graphHight, graphPixelsCur);
116 | delay(graphDelay);
117 | }
118 | delay(demoDelay);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/extras/hardware/1602_I2C_LCD_Display.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,2
3 | [InternetShortcut]
4 | URL=http://www.banggood.com/IIC-Or-I2C-Or-TWI-SPI-LCD1602-Character-LCD-Module-For-Arduino-p-88316.html?p=5G0704100426201212C9
5 | IDList=
6 |
--------------------------------------------------------------------------------
/extras/hardware/Blue_2004_I2C_LCD_Display.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,2
3 | [InternetShortcut]
4 | URL=http://www.banggood.com/IIC-Or-I2C-2004-204-20-X-4-Character-LCD-Display-Module-Blue-p-908616.html?p=5G0704100426201212C9
5 | IDList=
6 |
--------------------------------------------------------------------------------
/extras/hardware/I2C_Serial_LCD_Converter_Board_1602_2004.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,2
3 | [InternetShortcut]
4 | URL=http://www.banggood.com/IIC-Or-I2C-Or-TWI-Or-SP-Serial-Interface-Module-Port-For-5V-Arduino-1602LCD-p-80365.html?p=5G0704100426201212C9
5 | IDList=
6 |
--------------------------------------------------------------------------------
/extras/hardware/Yellow_Green_2004_I2C_LCD_Display.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,2
3 | [InternetShortcut]
4 | URL=http://www.banggood.com/IIC-Or-I2C-2004-204-20-X-4-Character-LCD-Display-Module-Yellow-Green-p-908821.html?p=5G0704100426201212C9
5 | IDList=
6 |
--------------------------------------------------------------------------------
/extras/info/2004_I2C_Serial_LCD_Display.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrkaleArduinoLib/LiquidCrystal_I2C/6e170491cccc3f8c5b889a214be428c223d12263/extras/info/2004_I2C_Serial_LCD_Display.jpg
--------------------------------------------------------------------------------
/extras/info/2004_Pinout.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrkaleArduinoLib/LiquidCrystal_I2C/6e170491cccc3f8c5b889a214be428c223d12263/extras/info/2004_Pinout.jpg
--------------------------------------------------------------------------------
/extras/info/Arduino I2C LCD.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,2
3 | [InternetShortcut]
4 | URL=http://playground.arduino.cc/Code/LCDi2c
5 | IDList=
6 | IconFile=http://playground.arduino.cc/favicon.png
7 | IconIndex=1
8 |
--------------------------------------------------------------------------------
/extras/info/Arduino LCD API.url:
--------------------------------------------------------------------------------
1 | [{000214A0-0000-0000-C000-000000000046}]
2 | Prop3=19,2
3 | [InternetShortcut]
4 | URL=http://playground.arduino.cc/Code/LCDAPI
5 | IDList=
6 |
--------------------------------------------------------------------------------
/extras/info/Character_Set.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrkaleArduinoLib/LiquidCrystal_I2C/6e170491cccc3f8c5b889a214be428c223d12263/extras/info/Character_Set.jpg
--------------------------------------------------------------------------------
/extras/info/Chinese_I2C_Serial_LCD_Converter_Board_1602_2004.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mrkaleArduinoLib/LiquidCrystal_I2C/6e170491cccc3f8c5b889a214be428c223d12263/extras/info/Chinese_I2C_Serial_LCD_Converter_Board_1602_2004.jpg
--------------------------------------------------------------------------------
/extras/info/readme.txt:
--------------------------------------------------------------------------------
1 | // LiquidCrystal_I2C V2.0 - Mario H. atmega@xs4all.nl
2 | // Mods for Chinese I2C converter board - Murray R. Van Luyn. vanluynm@iinet.net.au
3 |
4 | The LiquidCrystal_I2C library is a modified version of the standard LiquidCrystal library as found on
5 | the Arduino website.
6 | This library is intended to be used when a parallel HD44780 compatible LCD is controlled over I2C using
7 | a Chinese PCF8574 extender.
8 | 4 of the 8 outputs are used for LCD data lines 4 to 7.
9 | 4 outputs are used for the Enable, register-select, Read/Write and backlight control lines.
10 |
11 | The Chinese PCF8574 extender is available in two versions, the PCF8574 and the PCF8574A.
12 | The only difference between the two is the I2C base address.
13 | The base address for the PCF8574 is 0x27 and the base address for the PCF8574A is 0x4E.
14 | The examples included in this zip file assume the use of an PCF8574 set for address 0x27
15 | (A0, A1 and A3 un-linked, so pulled high).
16 |
17 | For PCF8574 the addressing is:
18 |
19 | Jp3 Jp2 Jp1
20 | A2 A1 A0 Dec Hex
21 | L L L 32 0x20
22 | L L H 33 0x21
23 | L H L 34 0x22
24 | L H H 35 0x23
25 | H L L 36 0x24
26 | H L H 37 0x25
27 | H H L 38 0x26
28 | H H H 39 0x27
29 |
30 | For PCF8574A the addressing is:
31 |
32 | Jp3 Jp2 Jp1
33 | A2 A1 A0 Dec Hex
34 | L L L 56 0x38
35 | L L H 57 0x39
36 | L H L 64 0x40
37 | L H H 74 0x4A
38 | H L L 75 0x4B
39 | H L H 76 0x4C
40 | H H L 77 0x4D
41 | H H H 78 0x4E
42 |
43 | For compatibility reasons this library contains some aliases for functions that are known under different
44 | names in other libraries. This should make it fairly easy to implement the library in existing sketches
45 | without changing to much code.
46 | Functions not supported by this library will return nothing at all and in case a return value is expected
47 | the function will return 0.
48 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | ###########################################
2 | # Syntax Coloring Map For LiquidCrystal_I2C
3 | ###########################################
4 |
5 | ###########################################
6 | # Datatypes (KEYWORD1)
7 | ###########################################
8 | LiquidCrystal_I2C KEYWORD1
9 |
10 | ###########################################
11 | # Methods and Functions (KEYWORD2)
12 | ###########################################
13 | init KEYWORD2
14 | begin KEYWORD2
15 | clear KEYWORD2
16 | home KEYWORD2
17 | noDisplay KEYWORD2
18 | display KEYWORD2
19 | noBlink KEYWORD2
20 | blink KEYWORD2
21 | noCursor KEYWORD2
22 | cursor KEYWORD2
23 | scrollDisplayLeft KEYWORD2
24 | scrollDisplayRight KEYWORD2
25 | leftToRight KEYWORD2
26 | rightToLeft KEYWORD2
27 | shiftIncrement KEYWORD2
28 | shiftDecrement KEYWORD2
29 | noBacklight KEYWORD2
30 | backlight KEYWORD2
31 | autoscroll KEYWORD2
32 | noAutoscroll KEYWORD2
33 | createChar KEYWORD2
34 | setCursor KEYWORD2
35 | print KEYWORD2
36 | blink_on KEYWORD2
37 | blink_off KEYWORD2
38 | cursor_on KEYWORD2
39 | cursor_off KEYWORD2
40 | setBacklight KEYWORD2
41 | load_custom_character KEYWORD2
42 | printstr KEYWORD2
43 | init_bargraph KEYWORD2
44 | draw_horizontal_graph KEYWORD2
45 | graphHorizontalChars KEYWORD2
46 | graphVerticalChars KEYWORD2
47 | ###########################################
48 | # Constants (LITERAL1)
49 | ###########################################
50 | LIQUIDCRYSTAL_I2C_VERSION LITERAL1
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=LiquidCrystal_I2C
2 | version=2.6.1
3 | author=Libor Gabaj
4 | maintainer=Libor Gabaj
5 | sentence=Library for parallel HD44780 compatible LCDs interfaced via a Chinese PCF8574 I2C serial extender.
6 | paragraph=Library for parallel HD44780 compatible LCDs interfaced via a Chinese PCF8574 I2C serial extender. It adds overloaded clear() function for clearing particular segment of an input row. Library also implements extended graph functions with help of custom characters and adds overloaded graph functions for expressing graph value in percentage or ration instead of pixels.
7 | category=Display
8 | url=https://github.com/mrkaleArduinoLib/LiquidCrystal_I2C.git
9 | architectures=avr
10 |
--------------------------------------------------------------------------------
/src/LiquidCrystal_I2C.cpp:
--------------------------------------------------------------------------------
1 | #include "LiquidCrystal_I2C.h"
2 |
3 | // When the display powers up, it is configured as follows:
4 | //
5 | // 1. Display clear
6 | // 2. Function set:
7 | // DL = 1; 8-bit interface data
8 | // N = 0; 1-line display
9 | // F = 0; 5x8 dot character font
10 | // 3. Display on/off control:
11 | // D = 0; Display off
12 | // C = 0; Cursor off
13 | // B = 0; Blinking off
14 | // 4. Entry mode set:
15 | // I/D = 1; Increment by 1
16 | // S = 0; No shift
17 | //
18 | // Note, however, that resetting the Arduino doesn't reset the LCD, so we
19 | // can't assume that its in that state when a sketch starts (and the
20 | // LiquidCrystal constructor is called).
21 | LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t addr, uint8_t cols, uint8_t rows)
22 | {
23 | _Addr = addr;
24 | _cols = cols;
25 | _rows = rows;
26 | _backlightval = LCD_NOBACKLIGHT;
27 | }
28 |
29 | void LiquidCrystal_I2C::init(){
30 | init_priv();
31 | }
32 |
33 | void LiquidCrystal_I2C::init_priv()
34 | {
35 | Wire.begin();
36 | _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
37 | begin(_cols, _rows);
38 | }
39 |
40 | void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t charsize) {
41 | if (lines > 1) {
42 | _displayfunction |= LCD_2LINE;
43 | }
44 | _numlines = lines;
45 |
46 | // for some 1 line displays you can select a 10 pixel high font
47 | if ((charsize != 0) && (lines == 1)) {
48 | _displayfunction |= LCD_5x10DOTS;
49 | }
50 |
51 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
52 | // according to datasheet, we need at least 40ms after power rises above 2.7V
53 | // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50
54 | delayMicroseconds(50000);
55 |
56 | // Now we pull both RS and R/W low to begin commands
57 | expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1)
58 | delay(1000);
59 |
60 | // put the LCD into 4 bit mode
61 | // this is according to the hitachi HD44780 datasheet
62 | // figure 24, pg 46
63 |
64 | // we start in 8bit mode, try to set 4 bit mode
65 | write4bits(0x30);
66 | delayMicroseconds(4500); // wait min 4.1ms
67 |
68 | // second try
69 | write4bits(0x30);
70 | delayMicroseconds(4500); // wait min 4.1ms
71 |
72 | // third go!
73 | write4bits(0x30);
74 | delayMicroseconds(150);
75 |
76 | // finally, set to 4-bit interface
77 | write4bits(0x20);
78 |
79 |
80 | // set # lines, font size, etc.
81 | command(LCD_FUNCTIONSET | _displayfunction);
82 |
83 | // turn the display on with no cursor or blinking default
84 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
85 | display();
86 |
87 | // clear it off
88 | clear();
89 |
90 | // Initialize to default text direction (for roman languages)
91 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
92 |
93 | // set the entry mode
94 | command(LCD_ENTRYMODESET | _displaymode);
95 |
96 | home();
97 |
98 | }
99 |
100 |
101 |
102 | /********** high level commands, for the user! */
103 | void LiquidCrystal_I2C::clear(){
104 | command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
105 | delayMicroseconds(2000); // this command takes a long time!
106 | }
107 |
108 | // Clear particular segment of a row
109 | void LiquidCrystal_I2C::clear(uint8_t rowStart, uint8_t colStart, uint8_t colCnt) {
110 | // Maintain input parameters
111 | rowStart = constrain(rowStart, 0, _rows - 1);
112 | colStart = constrain(colStart, 0, _cols - 1);
113 | colCnt = constrain(colCnt, 0, _cols - colStart);
114 | // Clear segment
115 | setCursor(colStart, rowStart);
116 | for (uint8_t i = 0; i < colCnt; i++) write(' ');
117 | // Go to segment start
118 | setCursor(colStart, rowStart);
119 | }
120 |
121 |
122 | void LiquidCrystal_I2C::home(){
123 | command(LCD_RETURNHOME); // set cursor position to zero
124 | delayMicroseconds(2000); // this command takes a long time!
125 | }
126 |
127 | void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
128 | int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
129 | if ( row > _numlines ) {
130 | row = _numlines-1; // we count rows starting w/0
131 | }
132 | command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
133 | }
134 |
135 | // Turn the display on/off (quickly)
136 | void LiquidCrystal_I2C::noDisplay() {
137 | _displaycontrol &= ~LCD_DISPLAYON;
138 | command(LCD_DISPLAYCONTROL | _displaycontrol);
139 | }
140 | void LiquidCrystal_I2C::display() {
141 | _displaycontrol |= LCD_DISPLAYON;
142 | command(LCD_DISPLAYCONTROL | _displaycontrol);
143 | }
144 |
145 | // Turns the underline cursor on/off
146 | void LiquidCrystal_I2C::noCursor() {
147 | _displaycontrol &= ~LCD_CURSORON;
148 | command(LCD_DISPLAYCONTROL | _displaycontrol);
149 | }
150 | void LiquidCrystal_I2C::cursor() {
151 | _displaycontrol |= LCD_CURSORON;
152 | command(LCD_DISPLAYCONTROL | _displaycontrol);
153 | }
154 |
155 | // Turn on and off the blinking cursor
156 | void LiquidCrystal_I2C::noBlink() {
157 | _displaycontrol &= ~LCD_BLINKON;
158 | command(LCD_DISPLAYCONTROL | _displaycontrol);
159 | }
160 | void LiquidCrystal_I2C::blink() {
161 | _displaycontrol |= LCD_BLINKON;
162 | command(LCD_DISPLAYCONTROL | _displaycontrol);
163 | }
164 |
165 | // These commands scroll the display without changing the RAM
166 | void LiquidCrystal_I2C::scrollDisplayLeft(void) {
167 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
168 | }
169 | void LiquidCrystal_I2C::scrollDisplayRight(void) {
170 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
171 | }
172 |
173 | // This is for text that flows Left to Right
174 | void LiquidCrystal_I2C::leftToRight(void) {
175 | _displaymode |= LCD_ENTRYLEFT;
176 | command(LCD_ENTRYMODESET | _displaymode);
177 | }
178 |
179 | // This is for text that flows Right to Left
180 | void LiquidCrystal_I2C::rightToLeft(void) {
181 | _displaymode &= ~LCD_ENTRYLEFT;
182 | command(LCD_ENTRYMODESET | _displaymode);
183 | }
184 |
185 | // This will 'right justify' text from the cursor
186 | void LiquidCrystal_I2C::autoscroll(void) {
187 | _displaymode |= LCD_ENTRYSHIFTINCREMENT;
188 | command(LCD_ENTRYMODESET | _displaymode);
189 | }
190 |
191 | // This will 'left justify' text from the cursor
192 | void LiquidCrystal_I2C::noAutoscroll(void) {
193 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
194 | command(LCD_ENTRYMODESET | _displaymode);
195 | }
196 |
197 | // Allows us to fill the first 8 CGRAM locations
198 | // with custom characters
199 | void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) {
200 | location &= 0x7; // we only have 8 locations 0-7
201 | command(LCD_SETCGRAMADDR | (location << 3));
202 | for (int i=0; i<8; i++) {
203 | write(charmap[i]);
204 | }
205 | }
206 |
207 | // Turn the (optional) backlight off/on
208 | void LiquidCrystal_I2C::noBacklight(void) {
209 | _backlightval=LCD_NOBACKLIGHT;
210 | expanderWrite(0);
211 | }
212 |
213 | void LiquidCrystal_I2C::backlight(void) {
214 | _backlightval=LCD_BACKLIGHT;
215 | expanderWrite(0);
216 | }
217 |
218 |
219 |
220 | /*********** mid level commands, for sending data/cmds */
221 |
222 | inline void LiquidCrystal_I2C::command(uint8_t value) {
223 | send(value, 0);
224 | }
225 |
226 | inline size_t LiquidCrystal_I2C::write(uint8_t value) {
227 | send(value, Rs);
228 | return 1; // Number of processed bytes
229 | }
230 |
231 |
232 |
233 | /************ low level data pushing commands **********/
234 |
235 | // write either command or data
236 | void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) {
237 | uint8_t highnib = value & 0xF0;
238 | uint8_t lownib = value << 4;
239 | write4bits((highnib)|mode);
240 | write4bits((lownib)|mode);
241 | }
242 |
243 | void LiquidCrystal_I2C::write4bits(uint8_t value) {
244 | expanderWrite(value);
245 | pulseEnable(value);
246 | }
247 |
248 | void LiquidCrystal_I2C::expanderWrite(uint8_t _data){
249 | Wire.beginTransmission(_Addr);
250 | Wire.write((int)(_data) | _backlightval);
251 | Wire.endTransmission();
252 | }
253 |
254 | void LiquidCrystal_I2C::pulseEnable(uint8_t _data){
255 | expanderWrite(_data | En); // En high
256 | delayMicroseconds(1); // enable pulse must be >450ns
257 |
258 | expanderWrite(_data & ~En); // En low
259 | delayMicroseconds(50); // commands need > 37us to settle
260 | }
261 |
262 | // Create custom characters for horizontal graphs
263 | uint8_t LiquidCrystal_I2C::graphHorizontalChars(uint8_t rowPattern) {
264 | uint8_t cc[LCD_CHARACTER_VERTICAL_DOTS];
265 | for (uint8_t idxCol = 0; idxCol < LCD_CHARACTER_HORIZONTAL_DOTS; idxCol++) {
266 | for (uint8_t idxRow = 0; idxRow < LCD_CHARACTER_VERTICAL_DOTS; idxRow++) {
267 | cc[idxRow] = rowPattern << (LCD_CHARACTER_HORIZONTAL_DOTS - 1 - idxCol);
268 | }
269 | createChar(idxCol, cc);
270 | }
271 | return LCD_CHARACTER_HORIZONTAL_DOTS;
272 | }
273 |
274 | // Create custom characters for vertical graphs
275 | uint8_t LiquidCrystal_I2C::graphVerticalChars(uint8_t rowPattern) {
276 | uint8_t cc[LCD_CHARACTER_VERTICAL_DOTS];
277 | for (uint8_t idxChr = 0; idxChr < LCD_CHARACTER_VERTICAL_DOTS; idxChr++) {
278 | for (uint8_t idxRow = 0; idxRow < LCD_CHARACTER_VERTICAL_DOTS; idxRow++) {
279 | cc[LCD_CHARACTER_VERTICAL_DOTS - idxRow - 1] = idxRow > idxChr ? B00000 : rowPattern;
280 | }
281 | createChar(idxChr, cc);
282 | }
283 | return LCD_CHARACTER_VERTICAL_DOTS;
284 | }
285 |
286 | // Initializes custom characters for input graph type
287 | uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype) {
288 | // Initialize row state vector
289 | for(byte i = 0; i < _rows; i++) {
290 | _graphstate[i] = 255;
291 | }
292 | switch (graphtype) {
293 | case LCDI2C_VERTICAL_BAR_GRAPH:
294 | graphVerticalChars(B11111);
295 | // Initialize column state vector
296 | for(byte i = _rows; i < _cols; i++) {
297 | _graphstate[i] = 255;
298 | }
299 | break;
300 | case LCDI2C_HORIZONTAL_BAR_GRAPH:
301 | graphHorizontalChars(B11111);
302 | break;
303 | case LCDI2C_HORIZONTAL_LINE_GRAPH:
304 | graphHorizontalChars(B00001);
305 | break;
306 | default:
307 | return 1;
308 | }
309 | _graphtype = graphtype;
310 | return 0;
311 | }
312 |
313 | // Display horizontal graph from desired cursor position with input value
314 | void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end) {
315 | // Maintain input parameters
316 | row = constrain(row, 0, _rows - 1);
317 | column = constrain(column, 0, _cols - 1);
318 | len = constrain(len, 0, _cols - column);
319 | pixel_col_end = constrain(pixel_col_end, 0, (len * LCD_CHARACTER_HORIZONTAL_DOTS) - 1);
320 | _graphstate[row] = constrain(_graphstate[row], column, column + len - 1);
321 | // Display graph
322 | switch (_graphtype) {
323 | case LCDI2C_HORIZONTAL_BAR_GRAPH:
324 | setCursor(column, row);
325 | // Display full characters
326 | for (uint8_t i = 0; i < pixel_col_end / LCD_CHARACTER_HORIZONTAL_DOTS; i++) {
327 | write(LCD_CHARACTER_HORIZONTAL_DOTS - 1);
328 | column++;
329 | }
330 | // Display last character
331 | write(pixel_col_end % LCD_CHARACTER_HORIZONTAL_DOTS);
332 | // Clear remaining chars in segment
333 | for (uint8_t i = column; i < _graphstate[row]; i++) write(' ');
334 | // Last drawn column as graph state
335 | _graphstate[row] = column;
336 | break;
337 | case LCDI2C_HORIZONTAL_LINE_GRAPH:
338 | // Drawn column as graph state
339 | column += pixel_col_end / LCD_CHARACTER_HORIZONTAL_DOTS;
340 | // Clear previous drawn character if differs from new one
341 | if (_graphstate[row] != column) {
342 | setCursor(_graphstate[row], row);
343 | write(' ');
344 | _graphstate[row] = column;
345 | }
346 | // Display graph character
347 | setCursor(column, row);
348 | write(pixel_col_end % LCD_CHARACTER_HORIZONTAL_DOTS);
349 | break;
350 | default:
351 | return;
352 | }
353 | }
354 | // Display horizontal graph from desired cursor position with input value
355 | void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end) {
356 | // Maintain input parameters
357 | row = constrain(row, 0, _rows - 1);
358 | column = constrain(column, 0, _cols - 1);
359 | len = constrain(len, 0, row + 1);
360 | pixel_row_end = constrain(pixel_row_end, 0, (len * LCD_CHARACTER_VERTICAL_DOTS) - 1);
361 | _graphstate[column] = constrain(_graphstate[column], row - len + 1, row);
362 | // Display graph
363 | switch (_graphtype) {
364 | case LCDI2C_VERTICAL_BAR_GRAPH:
365 | // Display full characters
366 | for (uint8_t i = 0; i < pixel_row_end / LCD_CHARACTER_VERTICAL_DOTS; i++) {
367 | setCursor(column, row--);
368 | write(LCD_CHARACTER_VERTICAL_DOTS - 1);
369 | }
370 | // Display the highest character
371 | setCursor(column, row);
372 | write(pixel_row_end % LCD_CHARACTER_VERTICAL_DOTS);
373 | // Clear remaining top chars in column
374 | for (uint8_t i = _graphstate[column]; i < row; i++) {
375 | setCursor(column, i);
376 | write(' ');
377 | }
378 | _graphstate[column] = row; // Last drawn row as its state
379 | break;
380 | default:
381 | return;
382 | }
383 | }
384 | // Overloaded methods
385 | void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint16_t percentage) {
386 | percentage = (percentage * len * LCD_CHARACTER_HORIZONTAL_DOTS / 100) - 1;
387 | draw_horizontal_graph(row, column, len, (uint8_t) percentage);
388 | }
389 | void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, float ratio) {
390 | ratio = (ratio * len * LCD_CHARACTER_HORIZONTAL_DOTS) - 1;
391 | draw_horizontal_graph(row, column, len, (uint8_t) ratio);
392 | }
393 | void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint16_t percentage) {
394 | percentage = (percentage * len * LCD_CHARACTER_VERTICAL_DOTS / 100) - 1;
395 | draw_vertical_graph(row, column, len, (uint8_t) percentage);
396 | }
397 | void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, float ratio) {
398 | ratio = (ratio * len * LCD_CHARACTER_VERTICAL_DOTS) - 1;
399 | draw_vertical_graph(row, column, len, (uint8_t) ratio);
400 | }
401 |
402 | // Alias functions
403 |
404 | void LiquidCrystal_I2C::on(){
405 | display();
406 | }
407 |
408 | void LiquidCrystal_I2C::off(){
409 | noDisplay();
410 | }
411 |
412 | void LiquidCrystal_I2C::cursor_on(){
413 | cursor();
414 | }
415 |
416 | void LiquidCrystal_I2C::cursor_off(){
417 | noCursor();
418 | }
419 |
420 | void LiquidCrystal_I2C::blink_on(){
421 | blink();
422 | }
423 |
424 | void LiquidCrystal_I2C::blink_off(){
425 | noBlink();
426 | }
427 |
428 | void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){
429 | createChar(char_num, rows);
430 | }
431 |
432 | void LiquidCrystal_I2C::setBacklight(uint8_t new_val){
433 | if(new_val){
434 | backlight(); // turn backlight on
435 | }else{
436 | noBacklight(); // turn backlight off
437 | }
438 | }
439 |
440 | void LiquidCrystal_I2C::printstr(const char c[]){
441 | //This function is not identical to the function used for "real" I2C displays
442 | //it's here so the user sketch doesn't have to be changed
443 | print(c);
444 | }
445 |
--------------------------------------------------------------------------------
/src/LiquidCrystal_I2C.h:
--------------------------------------------------------------------------------
1 | /*
2 | NAME:
3 | LiquidCrystal_I2C
4 |
5 | DESCRIPTION:
6 | Library for parallel HD44780 compatible LCDs interfaced via a Chinese
7 | PCF8574 I2C serial extender.
8 | - Library implements LCD API 1.0 to the extend the appropriate LCDs
9 | support functionality expected by the API.
10 | - Library adds overloaded clear() function for clearing particular
11 | segment of an input row.
12 | - Library implements extended graph functions with help of custom
13 | characters, so that do not use your custom characters concurrently
14 | with graph function. Your custom characters will be overwritten by
15 | graph initialization.
16 | - Library adds overloaded graph functions for expression graph value
17 | in percentage instead of pixels.
18 |
19 | LICENSE:
20 | This program is free software; you can redistribute it and/or modify
21 | it under the terms of the MIT License (MIT).
22 |
23 | CREDENTIALS:
24 | Author: Libor Gabaj
25 | GitHub: https://github.com/mrkaleArduinoLib/LiquidCrystal_I2C.git
26 |
27 | CREDITS:
28 | Mario H. atmega@xs4all.nl - LiquidCrystal_I2C V2.0
29 | Murray R. Van Luyn. vanluynm@iinet.net.au - Mods for Chinese I2C converter board
30 | */
31 | #ifndef LIQUIDCRYSTAL_I2C_H
32 | #define LIQUIDCRYSTAL_I2C_H
33 | #define LIQUIDCRYSTAL_I2C_VERSION "LiquidCrystal_I2C 2.6.1"
34 |
35 | #ifdef ARDUINO_ARCH_AVR
36 | #if ARDUINO >= 100
37 | #include "Arduino.h"
38 | #else
39 | #include "WProgram.h"
40 | #endif
41 | #include
42 | #endif
43 |
44 | // commands
45 | #define LCD_CLEARDISPLAY 0x01
46 | #define LCD_RETURNHOME 0x02
47 | #define LCD_ENTRYMODESET 0x04
48 | #define LCD_DISPLAYCONTROL 0x08
49 | #define LCD_CURSORSHIFT 0x10
50 | #define LCD_FUNCTIONSET 0x20
51 | #define LCD_SETCGRAMADDR 0x40
52 | #define LCD_SETDDRAMADDR 0x80
53 |
54 | // flags for display entry mode
55 | #define LCD_ENTRYRIGHT 0x00
56 | #define LCD_ENTRYLEFT 0x02
57 | #define LCD_ENTRYSHIFTINCREMENT 0x01
58 | #define LCD_ENTRYSHIFTDECREMENT 0x00
59 |
60 | // flags for display on/off control
61 | #define LCD_DISPLAYON 0x04
62 | #define LCD_DISPLAYOFF 0x00
63 | #define LCD_CURSORON 0x02
64 | #define LCD_CURSOROFF 0x00
65 | #define LCD_BLINKON 0x01
66 | #define LCD_BLINKOFF 0x00
67 |
68 | // flags for display/cursor shift
69 | #define LCD_DISPLAYMOVE 0x08
70 | #define LCD_CURSORMOVE 0x00
71 | #define LCD_MOVERIGHT 0x04
72 | #define LCD_MOVELEFT 0x00
73 |
74 | // flags for function set
75 | #define LCD_8BITMODE 0x10
76 | #define LCD_4BITMODE 0x00
77 | #define LCD_2LINE 0x08
78 | #define LCD_1LINE 0x00
79 | #define LCD_5x10DOTS 0x04
80 | #define LCD_5x8DOTS 0x00
81 |
82 | // flags for backlight control
83 | #define LCD_BACKLIGHT B00001000
84 | #define LCD_NOBACKLIGHT B00000000
85 |
86 | // values for graphtype in calls to init_bargraph and character geometry
87 | #define LCDI2C_VERTICAL_BAR_GRAPH 1
88 | #define LCDI2C_HORIZONTAL_BAR_GRAPH 2
89 | #define LCDI2C_HORIZONTAL_LINE_GRAPH 3
90 | #define LCD_CHARACTER_HORIZONTAL_DOTS 5
91 | #define LCD_CHARACTER_VERTICAL_DOTS 8
92 |
93 | #define En B00000100 // Enable bit
94 | #define Rw B00000010 // Read/Write bit
95 | #define Rs B00000001 // Register select bit
96 |
97 | class LiquidCrystal_I2C : public Print {
98 | public:
99 | LiquidCrystal_I2C(uint8_t addr, uint8_t cols, uint8_t rows);
100 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
101 | void init();
102 | /*
103 | Clear particular segment of a row
104 |
105 | DESCRIPTION:
106 | Overloaded original function clear().
107 | * Thanks to default parameters, for clearing the entire row
108 | use just clear(rowStart).
109 | * The functions sets the cursor to start column and row after clearing.
110 |
111 | PARAMETERS:
112 | rowStart - row number to be cleared counting from 0.
113 | Limited to the last row.
114 | colStart - column number of the cleared segment counting from 0.
115 | Defaulted to the very begining of the row.
116 | Limited to the last character.
117 | colCnt - number of cleared characters.
118 | Defaulted to 255.
119 | Limited to remaining characters on the row.
120 |
121 | RETURN: none
122 | */
123 | void clear();
124 | void clear(uint8_t rowStart, uint8_t colStart = 0, uint8_t colCnt = 255);
125 | void home();
126 | void noDisplay();
127 | void display();
128 | void noBlink();
129 | void blink();
130 | void noCursor();
131 | void cursor();
132 | void scrollDisplayLeft();
133 | void scrollDisplayRight();
134 | void leftToRight();
135 | void rightToLeft();
136 | void noBacklight();
137 | void backlight();
138 | void noAutoscroll();
139 | void autoscroll();
140 | void createChar(uint8_t location, uint8_t charmap[]);
141 | void setCursor(uint8_t col, uint8_t row);
142 | virtual size_t write(uint8_t value);
143 | void command(uint8_t value);
144 |
145 | /*
146 | Initialize particular bar graph
147 |
148 | DESCRIPTION:
149 | Creates a set of custom characters for displaying bar graphs.
150 | Some number of first current custom characters will be overwritten
151 | according to the type of graph.
152 |
153 | PARAMETERS:
154 | uint8_t graphtype - type of graph
155 | LCDI2C_VERTICAL_BAR_GRAPH - rewrites all 8 custom characters
156 | LCDI2C_HORIZONTAL_BAR_GRAPH - rewrites first 5 custom characters
157 | LCDI2C_HORIZONTAL_LINE_GRAPH - rewrites first 5 custom characters
158 |
159 | RETURN: error code
160 | 0 - at success
161 | 1 - at failure, e.g., graph type not recognized
162 | */
163 | uint8_t init_bargraph(uint8_t graphtype);
164 |
165 | /*
166 | Display horizontal graph from desired cursor position with input value
167 |
168 | DESCRIPTION:
169 | Displays horizontal bar or running pipe starting at input cursor position
170 | composed of custom characters.
171 | * For graph is reserved "len" characters long segment on the "row" starting
172 | on "column".
173 | * Current value of the bar graph is displayed as "pixel_col_end" pipes
174 | in the graph segment.
175 | * Current value of the line graph is displayed as pipe on "pixel_col_end"
176 | dot position in the graph segment.
177 | * Zero value of the graph is displayed as the very left pipe in the
178 | graph segment, so that the graph always displays something.
179 |
180 | PARAMETERS:
181 | uint8_t row - row position of graph segment counting from 0
182 | Limited to physical rows.
183 | uint8_t column - column position of graph segment counting from 0
184 | Limited to physical columns.
185 | uint8_t len - length of graph segment in characters
186 | Limited to remaining physical columns from col position.
187 | uint8_t pixel_col_end - value of graph in pipes counting from 0
188 | Limited to physical horizontal dots of graph segment.
189 |
190 | RETURN: none
191 | */
192 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end);
193 |
194 | /*
195 | Display vertical graph from desired cursor position with input value
196 |
197 | DESCRIPTION:
198 | Displays vertical bar starting at "row", "column" position composed
199 | of custom characters.
200 | For bar is reserved "len" rows long segment on the "column" starting on
201 | "row".
202 | Current value of the bar graph is displayed as "pixel_row_end" dashes
203 | from bottom to top of the graph segment.
204 |
205 | PARAMETERS:
206 | uint8_t row - row positon of the bottom of a graph segment
207 | counting from 0
208 | Limited to physical rows.
209 | uint8_t column - column position of graph segment counting from 0
210 | Limited to physical columns.
211 | uint8_t len - length of graph segment in rows
212 | Limited to remaining physical rows from row position.
213 | uint8_t pixel_row_end - value of graph in dashes counting from 0
214 | Limited to physical vertical dots of graph segment.
215 |
216 | RETURN: none
217 | */
218 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end);
219 |
220 | /*
221 | Overloaded methods with type difference of graph value
222 |
223 | PARAMETERS:
224 | uint16_t percentage - percentage of graph segment as graph value
225 | Although expected range is 0 to 100, uint8_t has been reserved
226 | by official API already.
227 | float ratio - fraction of graph segment as graph value
228 | Expected range is 0.0 to 1.0
229 | */
230 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint16_t percentage);
231 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, float ratio);
232 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint16_t percentage);
233 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, float ratio);
234 |
235 | ////compatibility API function aliases
236 | void on(); // alias for display()
237 | void off(); // alias for noDisplay()
238 | void blink_on(); // alias for blink()
239 | void blink_off(); // alias for noBlink()
240 | void cursor_on(); // alias for cursor()
241 | void cursor_off(); // alias for noCursor()
242 | void setBacklight(uint8_t new_val); // alias for backlight() and nobacklight()
243 | void load_custom_character(uint8_t char_num, uint8_t *rows); // alias for createChar()
244 | void printstr(const char[]);
245 |
246 | /* Unsupported API functions (not implemented in this library)
247 | uint8_t status();
248 | void setContrast(uint8_t new_val);
249 | uint8_t keypad();
250 | void setDelay(int, int);
251 | */
252 |
253 | private:
254 | void init_priv();
255 | void send(uint8_t, uint8_t);
256 | void write4bits(uint8_t);
257 | void expanderWrite(uint8_t);
258 | void pulseEnable(uint8_t);
259 |
260 | /*
261 | Create custom characters for horizontal graphs
262 |
263 | DESCRIPTION:
264 | Creates the set of custom characters for displaying horizontal graphs.
265 | The first 5 current custom characters will be overwritten.
266 | Particular custom characters are filled by bit shifting fullCharRowPattern
267 | from the right to the left.
268 |
269 | PARAMETERS:
270 | uint8_t rowPattern - row pattern of the full character
271 |
272 | RETURN: uint8_t - number of created custom characters
273 | */
274 | uint8_t graphHorizontalChars(uint8_t rowPattern);
275 |
276 | /*
277 | Create custom characters for vertical graphs
278 |
279 | DESCRIPTION:
280 | Creates the set of custom characters for displaying vertical graphs.
281 | All 8 current custom characters will be overwritten.
282 | Particular custom characters are filled with rowPattern from the very
283 | bottom pixel line.
284 |
285 | PARAMETERS:
286 | uint8_t rowPattern - row pattern of the pixel line
287 |
288 | RETURN: uint8_t - number of created custom characters
289 | */
290 | uint8_t graphVerticalChars(uint8_t rowPattern);
291 |
292 | // Private attributes
293 | uint8_t _Addr;
294 | uint8_t _displayfunction;
295 | uint8_t _displaycontrol;
296 | uint8_t _displaymode;
297 | uint8_t _numlines;
298 | uint8_t _cols;
299 | uint8_t _rows;
300 | uint8_t _backlightval;
301 | uint8_t _graphtype; // Internal code for graph type
302 | uint8_t _graphstate[20]; // Internal last graph column/row state
303 | };
304 |
305 | #endif
306 |
--------------------------------------------------------------------------------