        {
           // if there are no more packets on the radio, clear the receive flag;
           // otherwise, we want to handle the next packet on the next loop iteration.
-          digitalWrite(4, HIGH);
           rxflag = 0;
        }
        
        if (packet.type == MESSAGE)
        {
-         digitalWrite(13, HIGH);
+         
        }
     }  
 }
 
-//void handle_servo(){
-//  int val = analogRead(servo_x_pin);            // reads the value of the potentiometer (value between 0 and 1023) 
-//  val = map(val, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180) 
-//     
-//  //http://www.robotshop.com/blog/en/arduino-5-minute-tutorials-lesson-5-servo-motors-3636
-//  // Thanks Geoff and Adam!
-//  digitalWrite(servo_out_pin,HIGH);
-//  delayMicroseconds(val);
-//  digitalWrite(servo_out_pin,LOW);   
-//}
+void handle_servo(){
+   int val_x = analogRead(joystick_x_pin);            // reads the value of the potentiometer (value between 0 and 1023) 
+   int val_y = analogRead(joystick_y_pin);            // reads the value of the potentiometer (value between 0 and 1023) 
+   Serial.println(val_x);
+   Serial.println(val_y);
+}
   
 void setup() {
   pinMode(button_pin, INPUT);
-//  pinMode(servo_x_pin, INPUT);
-//  pinMode(servo_out_pin, OUTPUT);
-//  pinMode(IR_pin, OUTPUT);
-
-//   pinMode(13, OUTPUT);
-   pinMode(4, OUTPUT);
-   pinMode(10, OUTPUT); 
+  pinMode(joystick_x_pin, INPUT);
+  pinMode(joystick_y_pin, INPUT);
   
-   digitalWrite(4, LOW);
-   digitalWrite(10, LOW);
-   
+  pinMode(10, OUTPUT);    
+   digitalWrite(10, LOW);   
    delay(100);
    digitalWrite(10, HIGH);
    delay(100);

#include <SoftwareSerial.h>


#include <nRF24L01.h>
#include <packet.h>
#include <radio.h>
#include <spi.h>
#include <scheduler.h>

// constants won't change. They're used here to 
// set pin numbers:
const int button_pin = 2;
const int servo_x_pin = 0;
const int servo_out_pin = 9;
const int IR_pin = 13;

volatile uint8_t rxflag = 0; 
// packets are transmitted to this address
uint8_t station_addr[5] = { 0xAB, 0xAB, 0xAB, 0xAB, 0xAB };
// this is this radio's address
uint8_t my_addr[5] = { 0x18,0x2d,0x44,0x54,0xfb }; 
//uint8_t my_addr[5] = {'Z','Z','Z','Z','Z' }; 
radiopacket_t packet;


void check_button(){
  // read the state of the switch into a local variable:
  int val = analogRead(button_pin);
//  Serial.println(val);
  if( val < 50 ){
   // send the data
//   Serial.println((char *)packet.payload.message.messagecontent);
//   Serial.println((char *)packet.payload.message.address);

   for(int i = 0; i < 24; ++i){
    Serial.print(packet.payload.message.messagecontent[i]);
   }
   
   
   Radio_Transmit(&packet, RADIO_WAIT_FOR_TX);
  }
}

 
   // put some data into the packet
   packet.type = MESSAGE;
   for(int i = 0;i < 5; ++i){
    packet.payload.message.address[i] = my_addr[i];
   }

   for (int i = 0; i < 24; ++i) {
     packet.payload.message.messagecontent[i] = 'A' + i;
   }
   Radio_Set_Tx_Addr(station_addr);
   
  // Thanks Neil!  
  Scheduler_Init();
  Scheduler_StartTask(0,20,check_button);
  Scheduler_StartTask(5,20,recv_packet);
  Scheduler_StartTask(8,20,handle_servo);
}

void idle(uint32_t idle_period){
