I Update my Library on Arduino , Broke down my code . I want to create a bidirectional communication , read the temperature sensor on transmitter and send it to receiver and receiver will check if the temperature is over 25C , send a Flag or something to power on LED on transmitter , thanks for your help .
I used this Library : GitHub - maniacbug/RF24: Arduino driver for nRF24L01
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int val;
int tempPin = 0;
int LED = 2;
const byte pipe[2] ="00001";
int myFlag;
int thisMyFlag;
int temp1;
RF24 radio(9,10);
void setup()
{
pinMode(LED, OUTPUT);
radio.begin();
Serial.begin(9600);
radio.setRetries(15, 15);
radio.openReadingPipe(1, pipe[1]);
radio.startListening();
radio.printDetails();
}
void loop ()
{
chk_incoming();
delay(20);
chk_temp();
}
int chk_incoming()
{
if ( radio.available() )
{
int r = radio.read( &myFlag, sizeof(myFlag) );
Serial.println(r);
if (r == 1) {
digitalWrite(LED, HIGH);
}
}
}
void chk_temp()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
temp1 = int(cel) ;
TX_mode();
Serial.println(temp1);
}
void TX_mode()
{
radio.stopListening();
radio.openWritingPipe(pipe[1]);
bool ok = radio.write(&temp1 , sizeof(temp1) +1);
if (ok) {
radio.openReadingPipe(1, pipe[1]);
radio.startListening();
delay(200);
}
else {
printf("failednr");
}
}