Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a setAddress function #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions LiquidCrystal_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions LiquidCrystal_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
54 changes: 54 additions & 0 deletions examples/LiquidCrystalFindAddress/LiquidCrystalFindAddress.ino
Original file line number Diff line number Diff line change
@@ -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 <Wire.h>
#include <LiquidCrystal_I2C.h>

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);
}