#include <IRremote.h>
#include <LiquidCrystal.h>
int receiver = 2;
int a=0;
int b=0;
int input;
int hasil;
IRrecv irrecv(receiver);
decode_results results;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Memulai penerimaan sinyal I
}
void loop()
{
if (irrecv.decode()) {
lcd.clear();
button();
if (a == 0) {
a = input;
} else {
b = input;
}
lcd.setCursor(0, 0);
lcd.print(a);
lcd.print("+");
lcd.print(b);
lcd.print("=");
lcd.setCursor(5, 1);
if (a > 0 && b > 0) {
hasil = a + b;
}
Serial.print("input A:");
Serial.println(a);
Serial.print("input B:");
Serial.println(b);
Serial.print("Hasil :");
Serial.println(hasil);
lcd.print(hasil);
irrecv.resume();
}
}
void button(){
int IRinput = irrecv.decodedIRData.command;
if (IRinput == 48) { // angka 1
input= 1;
}
if (IRinput == 24) {
input= 2;
}
if (IRinput == 122) {
input= 3;
}
if (IRinput == 16) {
input= 4;
}
if (IRinput == 56) {
input= 5;
}
if (IRinput == 90) {
input= 6;
}
if (IRinput == 66) {
input= 7;
}
if (IRinput == 74) {
input= 8;
}
if (IRinput == 82) {
input= 9;
}
if (IRinput == 104) {
input= 0;
}
if (IRinput == 162) { // power
a = 0;
b = 0;
hasil = 0;
input = 0;
}
}