#include <IRremote.h>
#include <LiquidCrystal.h>
#include <Servo.h>
Servo pitch;// Create a "Servo" object called "pitch"
Servo yaw;// Create a "Servo" object called "Yaw"
Servo fire;// the one that shoots
float pitchpos = 0.0; // Variable where the pitch's pitchposition will be stored (in degrees)
float yawpos = 0.0; // Variable where the yaw's yawposition will be stored (in degrees)
float step = 5.0; // Variable used for the pitch's pitchposition step
#define PIN_RECEIVER 2 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
void setup()
{
receiver.enableIRIn(); // Start the receiver
pitch.attach(3); // Attache the pitch to the pin 3
pitch.write(pitchpos); // Initialize the pitch's pitchposition to 0 (leftmost)
yaw.attach(5); // Attache the yaw to the pin 5
yaw.write(yawpos); // Initialize the pitch's pitchposition to 0 (leftmost)
fire.attach(6); // Attache the fire to the pin 5
fire.write(0); // Initialize the pitch's pitchposition to 0 (leftmost)
}
void loop()
{
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 162:
Serial.print("POWER");
break;
case 226:
Serial.print("MENU");
break;
case 34:
Serial.print("TEST");
break;
case 2:
Serial.print("PLUS");
if (yawpos<180) // Check that the pitchposition won't go lower than 0°
{
yawpos+=step; // Decrement "pitchpos" of "step" value
yaw.write(yawpos); // Set the pitch's pitchposition to "pitchpos" value
delay(5); // Wait 5ms for the pitch to reach the pitchposition
}
break;
case 194:
Serial.print("BACK");
break;
case 224:
Serial.print("PREV.");
if (pitchpos>0) // Check that the pitchposition won't go lower than 0°
{
pitchpos-=step; // Decrement "pitchpos" of "step" value
pitch.write(pitchpos); // Set the pitch's pitchposition to "pitchpos" value
delay(5); // Wait 5ms for the pitch to reach the pitchposition
}
break;
case 168:
Serial.print("PLAY");
if(fire.read()==0)
{
fire.write(90);
delay(250);
fire.write(0);
delay(250);
}
break;
case 144:
Serial.print("NEXT");
if (pitchpos<180) // Check that the pitchposition won't go higher than 180°
{
pitchpos+=step; // Increment "pitchpos" of "step" value
pitch.write(pitchpos); // Set the pitch's pitchposition to "pitchpos" value
delay(5); // Wait 5ms for the pitch to reach the pitchposition
}
break;
case 104:
Serial.print("num: 0");
break;
case 152:
Serial.print("MINUS");
if (yawpos>0) // Check that the pitchposition won't go lower than 0°
{
yawpos-=step; // Decrement "pitchpos" of "step" value
yaw.write(yawpos); // Set the pitch's pitchposition to "pitchpos" value
delay(5); // Wait 5ms for the pitch to reach the pitchposition
}
break;
case 176:
Serial.print("key: C");
break;
case 48:
Serial.print("num: 1");
break;
case 24:
Serial.print("num: 2");
break;
case 122:
Serial.print("num: 3");
break;
case 16:
Serial.print("num: 4");
break;
case 56:
Serial.print("num: 5");
break;
case 90:
Serial.print("num: 6");
break;
case 66:
Serial.print("num: 7");
break;
case 74:
Serial.print("num: 8");
break;
case 82:
Serial.print("num: 9");
break;
default:
Serial.print("default");
}
}