#include <IRremote.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#define PIN_RECEIVER 2 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
Servo myservo;
int rotate = 0;
void setup()
{
lcd.begin(16, 2);
lcd.print("<press a button>");
receiver.enableIRIn(); // Start the receiver
myservo.attach(6);
}
void loop()
{
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
}
void lcdPrint(int val)
{
if(!((rotate == 0 && val == -1)||(rotate == 180 && val == 1))){
rotate += val;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("A11 - Yosfin");
lcd.setCursor(0, 1);
myservo.write(rotate);
lcd.print("Sudut:");
lcd.print(rotate);
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 2:
lcdPrint(1);
break;
case 152:
lcdPrint(-1);
break;
default:
lcd.clear();
lcd.print(receiver.decodedIRData.command);
lcd.print(" other button");
}
}