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

int switches = 0;
/*
*Arduino Final Bomb Pedistal
*Lucas Dahl
*2/6/2018
*
*/
  int lift = 0;
  int buttonState = 0;
RF24 radio(7, 8); // CE, CSN
const byte address[][6] = {"00001","00002","00003","00004"};
void setup() {
  radio.begin();
  
  radio.openWritingPipe(address[1]);
  //reads from reciever and sends to back room
  radio.openReadingPipe(0,address[2]);
  radio.setPALevel(RF24_PA_MIN);

  pinMode(6, INPUT);
  Serial.begin(9600);
}

//============================reads from safety recieve sends to backdoor
void loop() {
  delay(5);
  radio.stopListening();
  switches = digitalRead(6);
  if (switches == HIGH){
   bitWrite(lift,11,1);
 
      Serial.println("Door Open");
  }
  else{
     bitWrite(lift,11,0);
  
      //Serial.println(bitRead(lift,17));
  }
  Serial.println("HH");
     radio.write(&lift, sizeof(lift));
    delay(5);
    Serial.println("LL");

//----------------------start listening-----------    
  radio.startListening();

  delay(5);
    if (radio.available()){
     
     radio.read(&buttonState, sizeof(buttonState));
     }
  Serial.println(buttonState);

   lift = buttonState;

 // Serial.println(finaldoor);
  }
