diff --git a/LiquidCrystal_I2C.cpp b/LiquidCrystal_I2C.cpp index 44b7b05..bb07bb4 100644 --- a/LiquidCrystal_I2C.cpp +++ b/LiquidCrystal_I2C.cpp @@ -52,6 +52,10 @@ LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t l _backlightval = LCD_NOBACKLIGHT; } +void LiquidCrystal_I2C::setAddress(uint8_t lcd_Addr){ + _Addr = lcd_Addr; +} + void LiquidCrystal_I2C::init(){ init_priv(); } diff --git a/LiquidCrystal_I2C.h b/LiquidCrystal_I2C.h index c033f7f..fc38119 100644 --- a/LiquidCrystal_I2C.h +++ b/LiquidCrystal_I2C.h @@ -55,6 +55,7 @@ class LiquidCrystal_I2C : public Print { public: LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows); + void setAddress(uint8_t lcd_Addr); void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS ); void clear(); void home(); diff --git a/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino b/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino new file mode 100644 index 0000000..db7f018 --- /dev/null +++ b/examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino @@ -0,0 +1,54 @@ +/* + * This sketch will loop through adresses until it sees an I2C device + * When an address is found, we'll assume it's an Liquidcrystal I2C + * display and show the address there as well as on Serial. + * + * written by Jens Chr Brynildsen 2017 to help test 30 screens with + * varying I2C addresses. + */ + +//Compatible with the Arduino IDE 1.0 +//Library version:1.1 +#include +#include + +LiquidCrystal_I2C lcd(0, 20, 4); +int address; +char buff[10]; + +void setup() +{ + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + Wire.begin(); + delay(2000); + + for (address = 0; address <= 119; address++) { + Wire.beginTransmission(address); + int error = Wire.endTransmission(); + + if (error == 0) { // device found + sprintf(buff, "%02x", address); + Serial.print("Address: "); + Serial.println( buff ); + lcd.setAddress( address ); // set the address + lcd.init(); + lcd.backlight(); + lcd.setCursor(0, 0); + lcd.print("Hello world"); + lcd.setCursor(0, 1); + lcd.print("I2C addr: 0x"); + lcd.setCursor(12, 1); + lcd.print(buff); + while (1); + } + } +} + + +void loop() +{ + // if we reach this point, nothing was found on the I2C bus + digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN) ); + delay(100); +}