This is an example of how to user interrupts to interact with the radio, and a demonstration of how to use them to sleep when receiving, and not miss any payloads.
The pingpair_sleepy example expands on sleep functionality with a timed sleep option for the transmitter. Sleep functionality is built directly into my fork of the RF24Network library
29static uint32_t message_count = 1;
32byte address[][5] = { 0xCC, 0xCE, 0xCC, 0xCE, 0xCC, 0xCE, 0xCC, 0xCE, 0xCC, 0xCE };
41const short role_pin = 5;
42typedef enum { role_sender = 1,
43 role_receiver } role_e;
44const char* role_friendly_name[] = {
"invalid",
"Sender",
"Receiver" };
54 if (digitalRead(role_pin))
64 Serial.print(F(
"\n\rRF24/examples/pingpair_irq\n\rROLE: "));
65 Serial.println(role_friendly_name[role]);
73 radio.enableAckPayload();
74 radio.enableDynamicPayloads();
77 if (role == role_sender) {
78 radio.openWritingPipe(address[0]);
79 radio.openReadingPipe(1, address[1]);
81 radio.openWritingPipe(address[1]);
82 radio.openReadingPipe(1, address[0]);
83 radio.startListening();
86 radio.writeAckPayload(1, &message_count,
sizeof(message_count));
94 attachInterrupt(0, check_radio,
LOW);
103 if (role == role_sender) {
106 unsigned long time =
millis();
107 Serial.print(F(
"Now sending "));
108 Serial.println(time);
109 radio.startWrite(&time,
sizeof(
unsigned long), 0);
117 if (role == role_receiver) {}
124void check_radio(
void) {
127 radio.whatHappened(tx, fail, rx);
130 if (role == role_sender)
131 Serial.println(F(
"Send:OK"));
132 if (role == role_receiver)
133 Serial.println(F(
"Ack Payload:Sent"));
137 if (role == role_sender)
138 Serial.println(F(
"Send:Failed"));
139 if (role == role_receiver)
140 Serial.println(F(
"Ack Payload:Failed"));
143 if (rx || radio.available()) {
150 if (role == role_sender) {
152 radio.read(&message_count,
sizeof(message_count));
153 Serial.print(F(
"Ack: "));
154 Serial.println(message_count);
160 if (role == role_receiver) {
163 static unsigned long got_time;
164 radio.read(&got_time,
sizeof(got_time));
165 Serial.print(F(
"Got payload "));
166 Serial.println(got_time);
169 radio.writeAckPayload(1, &message_count,
sizeof(message_count));
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.
#define pinMode(pin, direction)
#define digitalWrite(pin, value)