Homepage Wiki Forum Buy

API LCD-4x20

From GNUBLIN

Contents


You can control GNUBLIN Module-LCD_2x20 easily with the API. The display uses the I2C-Connector.

At first, you have to construct an display object.

gnublin_module_lcd lcd;

After that, you are able to use following methods:

getErrorMessage();
fail();
setAddress(0x26);
setDevicefile("/dev/i2c-1");
init();
clear();
home();
setdisplay(0,1);
setcursor(1,1);
string("Hallo Welt");

lcd.getErrorMessage()

Description:

With that method you can return the last error message.

Syntax:

lcd.getErrorMessage();

Parameter:

None

Returns:

[const char*]ErrorMessage returns the last error message by a C-String


lcd.fail()

Description:

Evaluation of the error flags, if errors occur in the functions the error flag is set to true.

Syntax:

lcd.fail();

Parameter:

None

Returns:

[bool] true if there is an error, flase if not.


lcd.setAddress()

Description:

Set the I2C address of the modules lcd. If no address is set, the default address 0x20 is used.

Syntax:

lcd.setAddress(ADDRESS);

Parameter:

[int] ADDRESS: Adresse of lcd.

Returns:

[int]: by success 1, by -1


lcd.setDevicefile()

Description:

With this function you can change the Linux device file to which you are accessing. The default is "/dev/i2c-1" set.

Syntax:

 
lcd.setDevicefile(filename);

Parameter:

[sting] filename: You give the path to the dev-file in string format

Returns

None

lcd.init()

Description

This function initializes the display and provides an example text. As a result, you can see very quickly that the display works.

Syntax:

lcd.init();

Parameter:

None

Returns:

[int]: by success 1, by error -1


lcd.clear()

Description

Clears the complete display.

Syntax:

lcd.clear();

Parameter:

None

Returns:

[int]: by success 1, by error -1


lcd.home()

Description

Moves the cursor back to the beginning position to the upper left corner.

Syntax:

lcd.home();

Parameter:

None

Returns:

[int]: by success 1, by error -1


lcd.setdisplay(0,0)

Description

With this function, cursor settings can be made on the display.

Syntax:

lcd.setdisplay(int cursor, int blink);

Parameter:

[int] cursor 0: Cursor off, 1: Cursor on [int blink 0: Cursor doesnt flash, 1: The Cursor flashes.

Returns:

[int]: by success 1, by error -1



lcd.setcursor()

Description:

Moves the cursor to the given position on the screen.

Syntax:

lcd.setcursor(unsigned char x, unsigned char y);

Parameter:

[int] x desired column [int] y desired row

Returns:

[int]: by success 1, by error -1

lcd.string()

Description:

This function you are able to pass a string that should be shown on the display.

Syntax:

string(const char *data);

Parameter:

[const char*] data Char String, which should be displayed

Returns:

[int]: by success 1, by error -1


Examples

Simple display output

In this example, we want to make a simple display output.

#include "gnublin.h"
 
int main(){
  gnublin_module_lcd lcd;
 
  lcd.init();
  lcd.string("Hallo GNUBLIN");
}

Two line output

Here we want to print a text in each line of the display.

#include "gnublin.h"
 
char *version = (char *) "0.3";
 
int main(){
  gnublin_module_lcd lcd;
 
  lcd.init();
  lcd.setcursor(1, 1);
  lcd.string("embedded-projects");
  lcd.setcursor(2, 4);
  lcd.string("GNUBLIN-LCD");
  lcd.setcursor(3, 2);
  lcd.string("www.gnublin.org");
  lcd.setcursor(4, 4);
  lcd.string("Version ");
  lcd.string(version);
 
}


Kategorie:API

In other languages