#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 input = 2;
int pirState = LOW;
int val = 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(input, INPUT);
  
}
void loop() {
  val = digitalRead(input);
  if(val == HIGH){
    //Serial.println("High");
    if(pirState == LOW){
      Serial.println("MOTION"); 
      pirState = HIGH;
    }
  }else {
     //Serial.println("low");
     if (pirState== HIGH){
      Serial.println("No MOTION");
      pirState = LOW;
     }
  }
  
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    
  }
}
