Skip to content

Commit 3e9241f

Browse files
authored
Allow to couple/uncouple CE pin (#23)
Allow the specific display instance to be controlled by another instance, which has been initialized with the same pins except the CE one. Enables having multiple displays on the same data, clock and reset pins.
1 parent c012d0f commit 3e9241f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/Nokia_LCD.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ void Nokia_LCD::begin() {
112112
sendCommand(0x0C); // Set display control, normal mode.
113113
}
114114

115+
void Nokia_LCD::couple() {
116+
digitalWrite(kCe_pin, LOW);
117+
mCoupled = true;
118+
}
119+
void Nokia_LCD::uncouple() {
120+
digitalWrite(kCe_pin, HIGH);
121+
mCoupled = false;
122+
}
123+
115124
void Nokia_LCD::setContrast(uint8_t contrast) {
116125
sendCommand(0x21); // Tell LCD that extended commands follow
117126
sendCommand(0x80 | contrast); // Set LCD Vop (Contrast)
@@ -291,7 +300,9 @@ bool Nokia_LCD::send(const unsigned char lcd_byte, const bool is_data,
291300
digitalWrite(kDc_pin, is_data);
292301

293302
// Send the byte
294-
digitalWrite(kCe_pin, LOW);
303+
if (!mCoupled) {
304+
digitalWrite(kCe_pin, LOW);
305+
}
295306
if (kUsingHardwareSPI) {
296307
constexpr uint32_t kSPiClockSpeed{F_CPU / 4U};
297308
SPI.beginTransaction(SPISettings{kSPiClockSpeed, MSBFIRST, SPI_MODE0});
@@ -301,7 +312,9 @@ bool Nokia_LCD::send(const unsigned char lcd_byte, const bool is_data,
301312
shiftOut(kDin_pin, kClk_pin, MSBFIRST, lcd_byte);
302313
}
303314

304-
digitalWrite(kCe_pin, HIGH);
315+
if (!mCoupled) {
316+
digitalWrite(kCe_pin, HIGH);
317+
}
305318

306319
// If we just sent the command, there was no out-of-bounds error
307320
// and we don't have to calculate the new cursor position

src/Nokia_LCD.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ class Nokia_LCD {
231231
*/
232232
void setDefaultFont();
233233

234+
/**
235+
* @brief Allow the specific display instance to be controlled by another
236+
* instance, which has been initialized with the same pins except the CE one.
237+
* Enables having multiple displays on the same data, clock and reset pins.
238+
* @example Allow `lcd1` and `lcd2 to both display the same as `lcd3`
239+
* @example `lcd1.couple(); lcd2.couple(); lcd3.print("Hi there");`
240+
*/
241+
void couple();
242+
void uncouple();
243+
234244
private:
235245
/**
236246
* Sends the specified byte to the LCD via software SPI as data or a
@@ -275,6 +285,7 @@ class Nokia_LCD {
275285
*/
276286
bool printCharacter(char character);
277287

288+
bool mCoupled = false;
278289
const uint8_t kClk_pin, kDin_pin, kDc_pin, kCe_pin, kRst_pin, kBl_pin;
279290
bool mInverted = false;
280291
const bool kUsingBacklight;

0 commit comments

Comments
 (0)