#include <IRremote.h>
#include <LiquidCrystal_I2C.h>
#include <string.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int Cursor = 0;
int Line = 0;
IRrecv receiver(2);
String a = "";
String b = "";
void setup()
{
receiver.enableIRIn(); // Start the receiver
lcd.init();
lcd.backlight();
pinMode(A0, INPUT);
pinMode(A1, INPUT);
lcd.setCursor(0,0);
lcd.print("wuweiqi-finaltest");
}
void loop()
{
int y = analogRead(A0);
int x = analogRead(A1);
// Checks received an IR signal
if (receiver.decode()) {
lcd.clear();
translateIR();
b+=a;
lcd.setCursor(Cursor,Line);
lcd.print(b);
receiver.resume(); // Receive the next value
}
delay(100);
if(x<350 && Cursor<15){
lcd.clear();
lcd.setCursor(Cursor+=1,Line);
lcd.print(b);
}
if(x>650 && Cursor>0){
lcd.clear();
lcd.setCursor(Cursor-=1,Line);
lcd.print(b);
}
if(y<350 && Line==0){
lcd.clear();
lcd.setCursor(Cursor,Line+=1);
lcd.print(b);
}
if(y>650 && Line==1){
lcd.clear();
lcd.setCursor(Cursor,Line-=1);
lcd.print(b);
}
}
char translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 104:
a = "0";
break;
case 48:
a = "1";
break;
case 24:
a = "2";
break;
case 122:
a = "3";
break;
case 16:
a = "4";
break;
case 56:
a = "5";
break;
case 90:
a = "6";
break;
case 66:
a = "7";
break;
case 74:
a = "8";
break;
case 82:
a = "9";
break;
case 176:
a="";
b=b.substring(0,b.length()-1);
lcd.clear();
break;
default:
lcd.clear();
lcd.print(receiver.decodedIRData.command);
lcd.print(" other button");
}
}