#include <Wire.h> #include <LCD.h> #include <LiquidCrystal_I2C.h>
Next, you have to define several things which are (in the library) not suitable for my LCD module:
#define I2C_ADDR 0x20 #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 #define LED_OFF 1 #define LED_ON 0
Now you have to define the display:
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
Next, you can start in the setup()-function. At first, you have to tell the program what kind of display you have (the size, I have a 20 x 4 character display).
lcd.begin (20,4);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(LED_ON);
The rest is needed if you want to switch on the backlight with
lcd.backlight();
. Afterwards, the display is resetted: lcd.clear();
delay(1000);
lcd.home();
Now you can write things onto the display:
lcd.print("Hello, world!");
To place the cursor at a specified position, you have to do the following:
lcd.setCursor(5,1);
This should cover all basic functions. To delete everything, simply call
lcd.clear();
.A small hint, this problem took some time for me to solve: If you program an ATmega and then plug it into a pin board, usually nothing works, the ATmega needs a reset after it is plugged into the pin board. This could be caused by the fact that the ATmega already starts running when only some pins are connected to the pin board.
No comments:
Post a Comment