#include <RF24.h>
#include <nRF24L01.h>
#include <RF24_config.h>
#include <printf.h>

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/



*/


int val = 0;
    int finaldoor = 0;
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00002";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  pinMode(4, OUTPUT);
}
void loop() {
  
  if (radio.available()) {

    radio.read(&finaldoor, sizeof(finaldoor));
    Serial.println(finaldoor);
  }
  if( finaldoor == 1){
    digitalWrite(4, HIGH);
  }
  else {
    digitalWrite(4,LOW);
  }
}
