#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

#include <Servo.h>
Servo ConServo;
Servo StepServo;

unsigned int Angle = 0;
int SwitchState = 0;

void setup() {
  Serial.begin(9600);
  Mirf.cePin = 9; 
  Mirf.csnPin = 10;
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init(); //initialization
  
  Mirf.setRADDR((byte *)"Rec01");
  Mirf.payload = 2; //recieving 2 bytes 
  Mirf.channel = 3; // Sending channel (0~128)
  Mirf.config();

  ConServo.attach(6);  
  StepServo.attach(3);
  StepServo.write(90);
}

void loop() {
  byte data[Mirf.payload];
  if(Mirf.dataReady()) //Waiting to receive data. 
{
  Mirf.getData(data); //Receive data to data array. 
  Angle = (unsigned int)(data[0]); //to variables
  SwitchState = (int)(data[1]);
 
  Serial.print("Servo angle = ");
  Serial.print(Angle);
  Serial.print(";    Switch state = ");
  Serial.println(SwitchState);  
  }

  if (SwitchState == 0){
    ConServo.write(0); //rotate counterclockwise full speed (0-89)   
  }
  else{
    ConServo.write(90);
  }

  StepServo.write(Angle);
}
