#include <Servo.h>
#include <IRremote.h>
int Right = 144;
int Left = 224;
int Up= 2;
int Down= 152;
int Reset = 162;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
Servo servo1;
Servo servo2;
int command;
int pos_x = 90;
int pos_y = 90;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
irrecv.enableIRIn();
servo1.attach(10);
servo2.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
if (irrecv.decode()) {
//Serial.println("Received");
command = irrecv.decodedIRData.command;
button_commands();
irrecv.resume(); // Receive the next value
}
}
void button_commands(){
if(command == Left){
Serial.println(command);
pos_x = pos_x-2;
servo1.write(pos_x);
}
else if(command == Right){
pos_x = pos_x+2;
servo1.write(pos_x);
Serial.println(command);
}
else if(command == Up){
pos_y = pos_y+2;
servo2.write(pos_y);
Serial.println(command);
}
else if(command == Down){
pos_y = pos_y-2;
servo2.write(pos_y);
Serial.println(command);
}
else if(command == Reset){
servo1.write(90);
servo2.write(90);
pos_x = 90;
pos_y = 90;
Serial.println(command);
}
}