Example sketch showing how to create a simple messageing client with the NRF24 class. It is designed to work with the example nrf24_ping_server It also works with ping_server from the Mirf library
#include <NRF24.h>
#include <SPI.h>
void setup()
{
Serial.begin(9600);
while (!Serial)
;
Serial.println("NRF24 init failed");
Serial.println("setChannel failed");
Serial.println("setThisAddress failed");
Serial.println("setPayloadSize failed");
Serial.println("setRF failed");
Serial.println("initialised");
}
void loop()
{
Serial.println("setTransmitAddress failed");
unsigned long time = millis();
if (!nrf24.
send((uint8_t*)&time,
sizeof(time)))
Serial.println("send failed");
Serial.println("waitPacketSent failed");
{
unsigned long data;
uint8_t len = sizeof(data);
if (!nrf24.
recv((uint8_t*)&data, &len))
Serial.println("read failed");
unsigned long rtt = millis() - data;
Serial.print("Ping: ");
Serial.println(rtt);
}
else
Serial.println("No reply from server");
delay(1000);
}