#include <IRremote.h>
#include <Servo.h>
#define plus 0xFF18E7
#define minus 0xFF4AB5
int RECV_PIN = 3;
Servo servo;
int val;
bool cwRotation, ccwRotation;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
servo.attach(9);
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();
if (results.value == plus)
{
cwRotation = !cwRotation;
ccwRotation = false;
}
if (results.value == minus)
{
ccwRotation = !ccwRotation;
cwRotation = false;
}
}
if (cwRotation && (val != 175)) {
val++;
}
if (ccwRotation && (val != 0)) {
val--;
}
servo.write(val);
delay(20);
}