-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06dede8
commit 41cc694
Showing
15 changed files
with
555 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// | ||
// FILE: I2C_LCD.cpp | ||
// AUTHOR: [email protected] | ||
// VERSION: 0.1.3 | ||
// VERSION: 0.1.4 | ||
// DATE: 2023-12-16 | ||
// PUPROSE: Arduino library for I2C_LCD | ||
// 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_ | |
} | ||
|
||
|
||
void I2C_LCD::begin(uint8_t cols, uint8_t rows) | ||
bool I2C_LCD::begin(uint8_t cols, uint8_t rows) | ||
{ | ||
_cols = cols; | ||
_rows = rows; | ||
|
||
if (isConnected() == false) return false; | ||
|
||
// ALL LINES LOW. | ||
_wire->beginTransmission(_address); | ||
_wire->write(0x00); | ||
_wire->endTransmission(); | ||
|
||
// Figure 24 for procedure on 4-bit initialization | ||
// wait for more than 15 ms | ||
delay(100); // no need to optimize as this is called only once. | ||
// if other objects initialize earlier there will be less blocking time. | ||
while (millis() < 100) delay(1); | ||
|
||
// Force 4 bit mode | ||
write4bits(0x03); | ||
|
@@ -102,6 +105,7 @@ void I2C_LCD::begin(uint8_t cols, uint8_t rows) | |
// default enable display | ||
display(); | ||
clear(); | ||
return true; | ||
} | ||
|
||
|
||
|
@@ -118,7 +122,7 @@ bool I2C_LCD::isConnected() | |
// | ||
void I2C_LCD::setBacklightPin(uint8_t pin, uint8_t polarity) | ||
{ | ||
_backLightPin = ( 1 << pin); | ||
_backLightPin = (1 << pin); | ||
_backLightPol = polarity; | ||
} | ||
|
||
|
@@ -163,7 +167,7 @@ void I2C_LCD::clear() | |
|
||
void I2C_LCD::clearEOL() | ||
{ | ||
for (int i = _pos; i < _cols; i++) | ||
while(_pos < _cols) | ||
{ | ||
print(' '); | ||
} | ||
|
@@ -346,7 +350,7 @@ size_t I2C_LCD::write(uint8_t c) | |
size_t I2C_LCD::center(uint8_t row, const char * message) | ||
{ | ||
uint8_t len = strlen(message) + 1; | ||
setCursor(10 - len/2, row); | ||
setCursor((_cols - len) / 2, row); | ||
return print(message); | ||
} | ||
|
||
|
@@ -359,6 +363,17 @@ size_t I2C_LCD::right(uint8_t col, uint8_t row, const char * message) | |
} | ||
|
||
|
||
size_t I2C_LCD::repeat(uint8_t c, uint8_t times) | ||
{ | ||
size_t n = 0; | ||
while((times--) && (_pos < _cols)) | ||
{ | ||
n += write(c); | ||
} | ||
return n; | ||
} | ||
|
||
|
||
////////////////////////////////////////////////////////// | ||
// | ||
// PRIVATE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,19 @@ | |
// | ||
// FILE: I2C_LCD.h | ||
// AUTHOR: [email protected] | ||
// VERSION: 0.1.3 | ||
// VERSION: 0.1.4 | ||
// DATE: 2023-12-16 | ||
// PUPROSE: Arduino library for I2C_LCD | ||
// URL: https://github.com/RobTillaart/I2C_LCD | ||
|
||
|
||
#define I2C_LCD_LIB_VERSION (F("0.1.3")) | ||
#define I2C_LCD_LIB_VERSION (F("0.1.4")) | ||
|
||
#include "Arduino.h" | ||
#include "Wire.h" | ||
|
||
#ifndef POSITIVE | ||
#define POSITIVE 1 | ||
#endif | ||
|
||
#ifndef NEGATIVE | ||
#define NEGATIVE 0 | ||
#endif | ||
const uint8_t POSITIVE = 1; | ||
const uint8_t NEGATIVE = 0; | ||
|
||
|
||
class I2C_LCD : public Print | ||
|
@@ -34,8 +29,8 @@ class I2C_LCD : public Print | |
uint8_t backLight, uint8_t polarity); | ||
|
||
// only supports 5x8 char set for now. | ||
// blocks 100+ millisec to give device chance to reset | ||
void begin(uint8_t cols = 20, uint8_t rows = 4); | ||
// blocks up to 100 milliseconds to give LCD time to boot | ||
bool begin(uint8_t cols = 20, uint8_t rows = 4); | ||
bool isConnected(); | ||
|
||
|
||
|
@@ -86,6 +81,8 @@ class I2C_LCD : public Print | |
size_t write(uint8_t c); | ||
size_t center(uint8_t row, const char * message); | ||
size_t right(uint8_t col, uint8_t row, const char * message); | ||
size_t repeat(uint8_t c, uint8_t times); | ||
|
||
|
||
// DEBUG development | ||
uint8_t getColumn() { return _pos; }; // works. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#pragma once | ||
// | ||
// FILE: I2C_LCD_custom_chars.h | ||
// AUTHOR: [email protected] | ||
// VERSION: see library.properties | ||
// PUPROSE: Arduino library for I2C_LCD | ||
// URL: https://github.com/RobTillaart/I2C_LCD | ||
// https://maxpromer.github.io/LCD-Character-Creator/ | ||
// | ||
// See examples for some more | ||
|
||
|
||
//////////////////////////////////// | ||
// | ||
// Special | ||
// | ||
|
||
// one-liners easier to search? | ||
// uint8_t paragraph[] = { 0x06, 0x09, 0x04, 0x10, 0x04, 0x12, 0x0E, 0x00 }; | ||
|
||
uint8_t paragraph[] = { | ||
B00110, | ||
B01001, | ||
B00100, | ||
B01010, | ||
B00100, | ||
B10010, | ||
B01110, | ||
B00000 | ||
}; | ||
|
||
uint8_t copyRight[] = { | ||
B00000, | ||
B11111, | ||
B10001, | ||
B10111, | ||
B10111, | ||
B10001, | ||
B11111, | ||
B00000 | ||
}; | ||
|
||
|
||
//////////////////////////////////// | ||
// | ||
// Math | ||
// | ||
uint8_t lessThan[] = { | ||
B00000, | ||
B00010, | ||
B00100, | ||
B01000, | ||
B00100, | ||
B00010, | ||
B00000, | ||
B11111 | ||
}; | ||
|
||
uint8_t moreThan[] = { | ||
B00000, | ||
B01000, | ||
B00100, | ||
B00010, | ||
B00100, | ||
B01000, | ||
B00000, | ||
B11111 | ||
}; | ||
|
||
uint8_t notEqual[] = { | ||
B00000, | ||
B00010, | ||
B00010, | ||
B11111, | ||
B00100, | ||
B11111, | ||
B01000, | ||
B01000 | ||
}; | ||
|
||
//////////////////////////////////// | ||
// | ||
// ARROWS | ||
// | ||
uint8_t doubleUP[] = { | ||
B00100, | ||
B01110, | ||
B11111, | ||
B00000, | ||
B00100, | ||
B01110, | ||
B11111, | ||
B00000 | ||
}; | ||
|
||
uint8_t doubleDOWN[] = { | ||
B11111, | ||
B01110, | ||
B00100, | ||
B00000, | ||
B11111, | ||
B01110, | ||
B00100, | ||
B00000 | ||
}; | ||
|
||
uint8_t openUP[] = { | ||
B00000, | ||
B00100, | ||
B01010, | ||
B01010, | ||
B10001, | ||
B10001, | ||
B11111, | ||
B00000 | ||
}; | ||
|
||
uint8_t openDown[] = { | ||
B00000, | ||
B11111, | ||
B10001, | ||
B10001, | ||
B01010, | ||
B01010, | ||
B00100, | ||
B00000 | ||
}; | ||
|
||
//////////////////////////////////// | ||
// | ||
// BRACKETS --[]-- | ||
// | ||
uint8_t bracketRight[] = { | ||
B11100, | ||
B00100, | ||
B00100, | ||
B00111, | ||
B00100, | ||
B00100, | ||
B11100, | ||
B00000 | ||
}; | ||
|
||
uint8_t bracketLeft[] = { | ||
B00111, | ||
B00100, | ||
B00100, | ||
B11100, | ||
B00100, | ||
B00100, | ||
B00111, | ||
B00000 | ||
}; | ||
|
||
uint8_t singleLine[] = { | ||
B00000, | ||
B00000, | ||
B00000, | ||
B11111, | ||
B00000, | ||
B00000, | ||
B00000, | ||
B00000 | ||
}; | ||
|
||
uint8_t doubleLine[] = { | ||
B11111, | ||
B00000, | ||
B00000, | ||
B00000, | ||
B00000, | ||
B00000, | ||
B11111, | ||
B00000 | ||
}; | ||
|
||
|
||
//////////////////////////////////// | ||
// | ||
// Other | ||
// | ||
uint8_t OnOff[] = { | ||
B00100, | ||
B00100, | ||
B01110, | ||
B10101, | ||
B10101, | ||
B10001, | ||
B01110, | ||
B00000 | ||
}; | ||
|
||
uint8_t smiley[] = { | ||
B00000, | ||
B00000, | ||
B01010, | ||
B00000, | ||
B10001, | ||
B01110, | ||
B00000, | ||
B00000 | ||
}; | ||
|
||
uint8_t heart[] = { | ||
B00000, | ||
B01010, | ||
B10101, | ||
B10001, | ||
B01010, | ||
B00100, | ||
B00000, | ||
B00000 | ||
}; | ||
|
||
|
||
// -- END OF FILE -- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.