#include <LiquidCrystal_I2C.h>
#define sensor0 A0
#define sensor1 A1
#define sensor2 A2
#define sensor3 A3
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
byte sky[] = {
B00000,
B00000,
B00100,
B01110,
B00100,
B00000,
B00000,
B00000
};
byte ground[] = {
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B00000,
B00000
};
byte koreanG[] = {
B00000,
B00000,
B11111,
B00001,
B00001,
B00001,
B00001,
B00000
};
byte koreanN[] = {
B00000,
B00000,
B10000,
B10000,
B10000,
B10000,
B11111,
B00000
};
byte koreanD[] = {
B00000,
B00000,
B11111,
B10000,
B10000,
B10000,
B11111,
B00000
};
byte koreanB[] = {
B00000,
B10001,
B10001,
B11111,
B10001,
B10001,
B11111,
B00000
};
byte koreanS[] = {
B00000,
B00100,
B00100,
B01010,
B01010,
B10001,
B00000,
B00000
};
byte koreanJ[] = {
B00000,
B00000,
B11111,
B00010,
B00100,
B01010,
B10001,
B00000
};
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.createChar(0, koreanG); // ㄱ
lcd.createChar(1, koreanB); // ㅂ
lcd.createChar(2, sky); // +
lcd.createChar(3, koreanN); // ㄴ
lcd.createChar(4, koreanS); // ㅅ
lcd.createChar(5, ground); // ㅡ
lcd.createChar(6, koreanD); // ㄷ
lcd.createChar(7, koreanJ); // ㅈ
lcd.clear();
}
void loop() {
////////////적외선 센서 /////////////
float volts0 = analogRead(sensor0) * 0.0048828125;
int distance0 = 13 * pow(volts0, -1);
float volts1 = analogRead(sensor1) * 0.0048828125;
int distance1 = 13 * pow(volts1, -1);
float volts2 = analogRead(sensor2) * 0.0048828125;
int distance2 = 13 * pow(volts2, -1);
float volts3 = analogRead(sensor3) * 0.0048828125;
int distance3 = 13 * pow(volts3, -1);
///////////////////////// 적외선 1번 /////////////////////////////
if (4 <= distance0 && distance0 <= 30) {
if (4 <= distance0 && distance0 <= 12) {
lcd.write("I"); // ㅣ
delay(500);
}
else if (13 <= distance0 && distance0 <= 21) {
lcd.write(byte(0)); //
delay(500);
}
else if (22 <= distance0 && distance0 <= 30) {
lcd.write(byte(1)); //
delay(500);
}
}
/////////////////////////////적외선 2번 /////////////////////////
if (4 <= distance1 && distance1 <= 30) {
if (4 <= distance1 && distance1 <= 12) {
lcd.write(byte(2)); //
delay(500);
}
else if (13 <= distance1 && distance1 <= 21) {
lcd.write(byte(3)); //
delay(500);
}
else if (22 <= distance1 && distance1 <= 30) {
lcd.write(byte(4)); //
delay(500);
}
}
//////////////////////// 적외선 3번 //////////////////////////////
if (4 <= distance2 && distance2 <= 30) {
if (4 <= distance2 && distance2 <= 12) {
lcd.write(byte(5)); // ㅡ
delay(500);
}
else if (13 <= distance2 && distance2 <= 21) {
lcd.write(byte(6)); // ㅇ
delay(500);
}
else if (22 <= distance2 && distance2 <= 30) {
lcd.write(byte(7));
delay(500);
}
}
//////////////////////// 적외선 4번 ////////////////////////////////
if (4 <= distance3 && distance3 <= 30) {
if (4 <= distance3 && distance3 <= 12) {
lcd.print("O"); //o
delay(500);
}
else if (13 <= distance3 && distance3 <= 21) {
lcd.print("W"); // ㅈ
lcd.clear();
delay(500);
}
else if (22 <= distance3 && distance3 <= 30) {
lcd.clear();
delay(500);
}
}
}
제가 적외선 거리 감지 센서를 이용해서 거리에 따라서 LCD에 출력하는 글자를 다르게 해서 키보드 같은 걸 만들어 보고 있는데 적외선 감지 센서 오류가 많고 lcd 에 출력하다가 다음줄 넘어갈 때 너무 늦게 넘어갑니다. 코드에 문제점이 있을까요?
|