#include <SPI.h>
#include  <nRF24L01.h>
#include  <RF24.h>
RF24 radio(8, 10); // CE, CSN
const byte address[6] = "00001";
byte k = 0;
int myIR = A0;
byte N_pieces = 12; // nomber of pieces to count change it as you like
byte myLamp = 2;
void setup() {
  pinMode (myIR,INPUT); 
  pinMode(myLamp,OUTPUT);
  digitalWrite(myLamp,LOW);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  Serial.begin(9600);
}
void loop() {
  const char text[] = "yes"; 
    if (analogRead(A0) <= 500) { 
    k=k+1;
    Serial.println(k);
    delay(1000);
  }
  if(k >= N_pieces) {
  digitalWrite(myLamp,HIGH);
  radio.write(&text, sizeof(text));
  delay(250);
  }
}
