#include <Servo.h>
#include <IRremote.hpp>

// Define the pins for the servo and LEDs
int servoPin = 5;
int RedLed = 11;
int GreenLed = 10;

// Define the pins for the push buttons and IR receiver
int RedButton = 12;
int GreenButton = 9;
int irPin = 4;

// Define the servo object
Servo servo;

decode_results results;
#define code1 857// code recived from negative button
IRrecv irrecv(irPin);

void setup() {
  // Initialize the servo and set it to its initial position
  servo.attach(5);
  servo.write(90);
   Serial.begin(9600);
  irrecv.enableIRIn();
 
  // Initialize the LED pins as outputs
  pinMode(RedLed, OUTPUT);
  pinMode(GreenLed, OUTPUT);
 
  // Initialize the push button pins as inputs
  pinMode(RedButton, INPUT);
  pinMode(GreenButton, INPUT);
 
  // Initialize the IR receiver pin as input
  pinMode(irPin, INPUT);
}

void loop() {
  // Check if button 1 is pressed
  if (digitalRead(RedButton) == HIGH) {
    // Turn on LED 1
    digitalWrite(RedLed, HIGH);
   
    // Change the servo rotation direction
    servo.write(180);
  } else {
    // Turn off LED 1
    digitalWrite(RedLed, LOW);
  }
 
  // Check if button 2 is pressed
  if (digitalRead(GreenButton) == HIGH) {
    // Turn on LED 2
    digitalWrite(GreenLed, HIGH);
   
    // Change the servo rotation direction
    servo.write(0);
   
  }
  else {
    // Turn off LED 2
    digitalWrite(GreenLed, LOW);
  }
 if (results.value == 0x857)
    // Read the signal from the remote
    {
    servo.write (90);
    }
}
