Skip to content

Commit 41cc694

Browse files
committed
0.1.4 I2C_LCD
1 parent 06dede8 commit 41cc694

File tree

15 files changed

+555
-58
lines changed

15 files changed

+555
-58
lines changed

libraries/I2C_LCD/CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.1.4] - 2023-12-28
10+
- changed return type of **begin()**. Returns false if LCD not found on I2C bus.
11+
- made initialization delay(100) in **begin()** a bit smarter.
12+
- add **repeat(c, times)**
13+
- fix **center()** for non 20x4 LCD.
14+
- add **I2C_LCD_custom_chars.h** with examples.
15+
- add examples
16+
17+
918
## [0.1.3] - 2023-12-22
10-
- add support for **16x4** + **10x4** display
19+
- add support for **16x4** and **10x4** display.
1120
- minimized footprint **setCursor()**
1221
- add parameter to **moveCursorLeft(uint8_t n = 1)**
1322
- add parameter to **moveCursorRight(uint8_t n = 1)**
1423
- improve timing
1524
- update examples
1625
- minor edits
1726

18-
1927
## [0.1.2] - 2023-12-21
2028
- implement polarity backlight (and removed policy)
2129
- add **size_t center(uint8_t row, const char \* message)**

libraries/I2C_LCD/I2C_LCD.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: I2C_LCD.cpp
33
4-
// VERSION: 0.1.3
4+
// VERSION: 0.1.4
55
// DATE: 2023-12-16
66
// PUPROSE: Arduino library for I2C_LCD
77
// URL: https://github.com/RobTillaart/I2C_LCD
@@ -71,19 +71,22 @@ void I2C_LCD::config (uint8_t address, uint8_t enable, uint8_t readWrite, uint8_
7171
}
7272

7373

74-
void I2C_LCD::begin(uint8_t cols, uint8_t rows)
74+
bool I2C_LCD::begin(uint8_t cols, uint8_t rows)
7575
{
7676
_cols = cols;
7777
_rows = rows;
7878

79+
if (isConnected() == false) return false;
80+
7981
// ALL LINES LOW.
8082
_wire->beginTransmission(_address);
8183
_wire->write(0x00);
8284
_wire->endTransmission();
8385

8486
// Figure 24 for procedure on 4-bit initialization
8587
// wait for more than 15 ms
86-
delay(100); // no need to optimize as this is called only once.
88+
// if other objects initialize earlier there will be less blocking time.
89+
while (millis() < 100) delay(1);
8790

8891
// Force 4 bit mode
8992
write4bits(0x03);
@@ -102,6 +105,7 @@ void I2C_LCD::begin(uint8_t cols, uint8_t rows)
102105
// default enable display
103106
display();
104107
clear();
108+
return true;
105109
}
106110

107111

@@ -118,7 +122,7 @@ bool I2C_LCD::isConnected()
118122
//
119123
void I2C_LCD::setBacklightPin(uint8_t pin, uint8_t polarity)
120124
{
121-
_backLightPin = ( 1 << pin);
125+
_backLightPin = (1 << pin);
122126
_backLightPol = polarity;
123127
}
124128

@@ -163,7 +167,7 @@ void I2C_LCD::clear()
163167

164168
void I2C_LCD::clearEOL()
165169
{
166-
for (int i = _pos; i < _cols; i++)
170+
while(_pos < _cols)
167171
{
168172
print(' ');
169173
}
@@ -346,7 +350,7 @@ size_t I2C_LCD::write(uint8_t c)
346350
size_t I2C_LCD::center(uint8_t row, const char * message)
347351
{
348352
uint8_t len = strlen(message) + 1;
349-
setCursor(10 - len/2, row);
353+
setCursor((_cols - len) / 2, row);
350354
return print(message);
351355
}
352356

@@ -359,6 +363,17 @@ size_t I2C_LCD::right(uint8_t col, uint8_t row, const char * message)
359363
}
360364

361365

366+
size_t I2C_LCD::repeat(uint8_t c, uint8_t times)
367+
{
368+
size_t n = 0;
369+
while((times--) && (_pos < _cols))
370+
{
371+
n += write(c);
372+
}
373+
return n;
374+
}
375+
376+
362377
//////////////////////////////////////////////////////////
363378
//
364379
// PRIVATE

libraries/I2C_LCD/I2C_LCD.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22
//
33
// FILE: I2C_LCD.h
44
5-
// VERSION: 0.1.3
5+
// VERSION: 0.1.4
66
// DATE: 2023-12-16
77
// PUPROSE: Arduino library for I2C_LCD
88
// URL: https://github.com/RobTillaart/I2C_LCD
99

1010

11-
#define I2C_LCD_LIB_VERSION (F("0.1.3"))
11+
#define I2C_LCD_LIB_VERSION (F("0.1.4"))
1212

1313
#include "Arduino.h"
1414
#include "Wire.h"
1515

16-
#ifndef POSITIVE
17-
#define POSITIVE 1
18-
#endif
19-
20-
#ifndef NEGATIVE
21-
#define NEGATIVE 0
22-
#endif
16+
const uint8_t POSITIVE = 1;
17+
const uint8_t NEGATIVE = 0;
2318

2419

2520
class I2C_LCD : public Print
@@ -34,8 +29,8 @@ class I2C_LCD : public Print
3429
uint8_t backLight, uint8_t polarity);
3530

3631
// only supports 5x8 char set for now.
37-
// blocks 100+ millisec to give device chance to reset
38-
void begin(uint8_t cols = 20, uint8_t rows = 4);
32+
// blocks up to 100 milliseconds to give LCD time to boot
33+
bool begin(uint8_t cols = 20, uint8_t rows = 4);
3934
bool isConnected();
4035

4136

@@ -86,6 +81,8 @@ class I2C_LCD : public Print
8681
size_t write(uint8_t c);
8782
size_t center(uint8_t row, const char * message);
8883
size_t right(uint8_t col, uint8_t row, const char * message);
84+
size_t repeat(uint8_t c, uint8_t times);
85+
8986

9087
// DEBUG development
9188
uint8_t getColumn() { return _pos; }; // works.
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
#pragma once
2+
//
3+
// FILE: I2C_LCD_custom_chars.h
4+
5+
// VERSION: see library.properties
6+
// PUPROSE: Arduino library for I2C_LCD
7+
// URL: https://github.com/RobTillaart/I2C_LCD
8+
// https://maxpromer.github.io/LCD-Character-Creator/
9+
//
10+
// See examples for some more
11+
12+
13+
////////////////////////////////////
14+
//
15+
// Special
16+
//
17+
18+
// one-liners easier to search?
19+
// uint8_t paragraph[] = { 0x06, 0x09, 0x04, 0x10, 0x04, 0x12, 0x0E, 0x00 };
20+
21+
uint8_t paragraph[] = {
22+
B00110,
23+
B01001,
24+
B00100,
25+
B01010,
26+
B00100,
27+
B10010,
28+
B01110,
29+
B00000
30+
};
31+
32+
uint8_t copyRight[] = {
33+
B00000,
34+
B11111,
35+
B10001,
36+
B10111,
37+
B10111,
38+
B10001,
39+
B11111,
40+
B00000
41+
};
42+
43+
44+
////////////////////////////////////
45+
//
46+
// Math
47+
//
48+
uint8_t lessThan[] = {
49+
B00000,
50+
B00010,
51+
B00100,
52+
B01000,
53+
B00100,
54+
B00010,
55+
B00000,
56+
B11111
57+
};
58+
59+
uint8_t moreThan[] = {
60+
B00000,
61+
B01000,
62+
B00100,
63+
B00010,
64+
B00100,
65+
B01000,
66+
B00000,
67+
B11111
68+
};
69+
70+
uint8_t notEqual[] = {
71+
B00000,
72+
B00010,
73+
B00010,
74+
B11111,
75+
B00100,
76+
B11111,
77+
B01000,
78+
B01000
79+
};
80+
81+
////////////////////////////////////
82+
//
83+
// ARROWS
84+
//
85+
uint8_t doubleUP[] = {
86+
B00100,
87+
B01110,
88+
B11111,
89+
B00000,
90+
B00100,
91+
B01110,
92+
B11111,
93+
B00000
94+
};
95+
96+
uint8_t doubleDOWN[] = {
97+
B11111,
98+
B01110,
99+
B00100,
100+
B00000,
101+
B11111,
102+
B01110,
103+
B00100,
104+
B00000
105+
};
106+
107+
uint8_t openUP[] = {
108+
B00000,
109+
B00100,
110+
B01010,
111+
B01010,
112+
B10001,
113+
B10001,
114+
B11111,
115+
B00000
116+
};
117+
118+
uint8_t openDown[] = {
119+
B00000,
120+
B11111,
121+
B10001,
122+
B10001,
123+
B01010,
124+
B01010,
125+
B00100,
126+
B00000
127+
};
128+
129+
////////////////////////////////////
130+
//
131+
// BRACKETS --[]--
132+
//
133+
uint8_t bracketRight[] = {
134+
B11100,
135+
B00100,
136+
B00100,
137+
B00111,
138+
B00100,
139+
B00100,
140+
B11100,
141+
B00000
142+
};
143+
144+
uint8_t bracketLeft[] = {
145+
B00111,
146+
B00100,
147+
B00100,
148+
B11100,
149+
B00100,
150+
B00100,
151+
B00111,
152+
B00000
153+
};
154+
155+
uint8_t singleLine[] = {
156+
B00000,
157+
B00000,
158+
B00000,
159+
B11111,
160+
B00000,
161+
B00000,
162+
B00000,
163+
B00000
164+
};
165+
166+
uint8_t doubleLine[] = {
167+
B11111,
168+
B00000,
169+
B00000,
170+
B00000,
171+
B00000,
172+
B00000,
173+
B11111,
174+
B00000
175+
};
176+
177+
178+
////////////////////////////////////
179+
//
180+
// Other
181+
//
182+
uint8_t OnOff[] = {
183+
B00100,
184+
B00100,
185+
B01110,
186+
B10101,
187+
B10101,
188+
B10001,
189+
B01110,
190+
B00000
191+
};
192+
193+
uint8_t smiley[] = {
194+
B00000,
195+
B00000,
196+
B01010,
197+
B00000,
198+
B10001,
199+
B01110,
200+
B00000,
201+
B00000
202+
};
203+
204+
uint8_t heart[] = {
205+
B00000,
206+
B01010,
207+
B10101,
208+
B10001,
209+
B01010,
210+
B00100,
211+
B00000,
212+
B00000
213+
};
214+
215+
216+
// -- END OF FILE --
217+

libraries/I2C_LCD/I2C_LCD_special_chars.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
// URL: https://github.com/RobTillaart/I2C_LCD
99

1010

11-
// SPECIAL CHARS, might not work on all displays.
11+
// SPECIAL CHARS,
12+
// will only work on displays with ROM CODE A00
13+
//
1214

1315
const char LCD_ALPHA = 0xE0;
1416
const char LCD_BETA = 0xE2;
1517
const char LCD_EPSILON = 0xE3;
1618
const char LCD_MU = 0xE4;
1719
const char LCD_RHO = 0xE5;
20+
const char LCD_SQROOT = 0xE7;
21+
1822
const char LCD_THETA = 0xF2;
1923
const char LCD_INFINITY = 0xF3;
2024
const char LCD_OHM = 0xF4;

0 commit comments

Comments
 (0)