2024-05-14 16:11:08 +03:00

52 lines
942 B
C++

//Receiver program
#include "Mirf.h"
Nrf24l Mirf = Nrf24l(10, 9); // CE,CSN
struct Pack {
byte index;
char payload[31];
};
#define PackSize sizeof(Pack)
union MYDATA_t {
byte value[PackSize];
struct Pack pack;
};
MYDATA_t mydata;
void setup()
{
Serial.begin(115200);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = sizeof(mydata.value); // Set the payload size
Mirf.channel = 90; // Set the used channel
Mirf.config();
// Set my own address to RX_ADDR_P1
Mirf.setRADDR((byte *)"FGHIJ");
// Clear RX FiFo
while(1) {
if (Mirf.dataReady() == false) break;
Mirf.getData(mydata.value);
}
Serial.println("Listening...");
}
void loop()
{
// Wait for received data
if (Mirf.dataReady()) {
Mirf.getData(mydata.value);
Serial.print("Got index=");
Serial.print(mydata.pack.index);
Serial.print(" payload=");
Serial.println(mydata.pack.payload);
}
}