EdrawMax사용 예정
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
void loop()
{
}
LiquidCrystal_I2C 라이브러리를 설치하면 example폴더에 있는 예제 코드이다. 그러나 실행 결과 각 문자열의 첫 글자만 출력 되었다. 따라서 임시 방편으로 다음과 같이 코드를 수정했다.#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
lcd.init();
lcd.backlight();
String str = "Hello, world!";
for (int i = 0; i < str.length(); i ++) {
lcd.setCursor(i, 0);
lcd.print(str[i]);
}
}
void loop()
{
}
추후 근본적인 원인을 찾아 해결할 예정이다. 현재는 lcdPrint 함수를 따로 만들어 아래와 같이 사용하도록 한다.#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
lcd.init();
lcd.backlight();
String str = "Hello, world!";
lcdPrint(str, 0, 0);
}
void loop()
{
}
void lcdPrint(String str, int x, int y) {
for (int i = 0; i < str.length(); i ++) {
lcd.setCursor(x + i, y);
lcd.print(str[i]);
}
}