Files
remote/Nrf.h
T

44 lines
1.0 KiB
C
Raw Normal View History

2019-05-26 22:29:00 +02:00
#include <SPI.h>
#include "RF24.h"
2019-05-26 22:58:04 +02:00
#include <RF24Network.h>
2019-05-26 22:29:00 +02:00
#include "TransferDataStructure.h"
// Nrf24 settings
RF24 radio(9, 10); // CE, CSN
2019-05-26 22:58:04 +02:00
RF24Network network(radio);
const uint16_t this_node = 00; // Address of our node in Octal format
const uint16_t other_node = 01; // Address of the other node in Octal format
2019-05-26 22:29:00 +02:00
void NrfInit()
{
2019-05-26 22:58:04 +02:00
SPI.begin();
2019-05-26 22:29:00 +02:00
radio.begin();
2019-05-26 22:58:04 +02:00
network.begin(/*channel*/ 90, /*node address*/ this_node);
2019-05-26 22:29:00 +02:00
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_LOW);
}
dataStruct2 NrfSendData(dataStruct2 data, bool debug = false)
{
2019-05-26 22:58:04 +02:00
network.update();
2019-05-26 22:29:00 +02:00
if (debug)
2019-05-26 22:58:04 +02:00
Serial.print("Sending...");
2019-05-26 22:29:00 +02:00
2019-05-26 22:58:04 +02:00
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header, &data, sizeof(data));
if (debug)
{
if (ok)
Serial.println("ok.");
else
Serial.println("failed.");
2019-05-26 22:29:00 +02:00
}
2019-05-26 22:58:04 +02:00
return data;
2019-05-26 22:29:00 +02:00
}