#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include<printf.h>
//#define LOG_AVERAGE 0
//#define LOG_TIMESTAMP 0
//#define VCC_SUPPLY 5
//#define AVG_NUM 20
//#define R1
//#define R2
#define Rref
#define Vout
//float avg[ AVG_NUM ];
//int num = 0;
//int idx = 0;
//float sum = 0;;
RF24 radio(5,6); // CE, CSN
const byte rxAddr[6] = "00001";
int remoteNodeData[2] = {1,1}; //simple integer array for remote node data, in the form(node_id, returned_count)
int dataFromMaster = 0; //integer to store count of successful transmisiions
#define NUM_CHANNELS 1
typedef struct {
long int td; //4 bytes
int data[ NUM_CHANNELS ]; //2 x 6 = 12 bytes
} SRF24_Data;
SRF24_Data RData;
SRF24_Data* pSRData = &RData;
void setup()
{
while (!Serial);
//if (radio.available()){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, rxAddr);
//radio.setPALevel(RF_24_PA_MIN);
//radio.setDataRate(RF_24_250KBPS);
radio.setChannel(0x76);
radio.enableAckPayload();// enable ack payload - slave replies with data using this feature
// radio.writeAckPayload(&SRF24_Data, sizeof(SR24_Data)); // preload the payload with intial data- sent after an incoming message is read
// printf_begin();
//radio.printDetails();
radio.startListening();
}
//#define PRIMARY_VOLTAGE_DIVIDER_REF 47 //In KOhms
long int t;
long int lastTd;
//long int seq_number=0;
void loop()
{
if (radio.available()){
long int t;
}
radioCheckAndReply();
pSRData->td = millis( );
radio.read(pSRData, sizeof( SRF24_Data ) );
Serial.print(pSRData->td);
Serial.print("Mathew");
delay(1000);
}
void radioCheckAndReply(void)
//{
// if (radio.available())
{
radio.read(&dataFromMaster, sizeof(dataFromMaster));
Serial.println(" Received request from master - sending preloaded data.");
// long int t;
char text[32] = {};
radio.read(&text, sizeof(text));
Serial.println(text);
// pSRData->td = millis( );
//radio.read(pSRData, sizeof( SRF24_Data ) );
//Serial.print(pSRData->td);
//Serial.print("Mathew");
//delay(1000);
}