So I attempted to add some elements to your Rx ack payload code from one of my other project's code but I don't think I added it correctly. Here is the code that I added elements from.
void setup() {
Serial.begin(9600);
pinMode(11, OUTPUT); // put your setup code here, to run once:
pinMode(8, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
char data= Serial.read(); // reading the data received from the bluetooth module
switch(data)
{
case 'a': digitalWrite(13, HIGH);break; // when a is pressed on the app on your smart phone
case 'd': digitalWrite(13, LOW);break; // when d is pressed on the app on your smart phone
case 'b': digitalWrite(8, HIGH);break;
case 'c': digitalWrite(8, LOW);break;
case 'e': digitalWrite(5, HIGH);break;
case 'f': digitalWrite(5, LOW);break;
default : break;
}
Serial.println(data);
}
delay(50) ;
}
This is your code with what I added to it.
// SimpleRxAckPayload- the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
char dataReceived[10]; // this must match dataToSend in the TX
int ackData[2] = {109, -4000}; // the two values to be sent to the master
bool newData = false;
//==============
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
Serial.println("SimpleRxAckPayload Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.enableAckPayload();
radio.startListening();
radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data
}
//==========
void loop() {
getData();
showData();
}
//============
void getData() {
if ( radio.available() ) {
radio.read( &dataReceived, sizeof(dataReceived) );
updateReplyData();
newData = true;
}
}
//================
void showData() {
if (newData == true) {
Serial.print("Data received ");
Serial.println(dataReceived);
Serial.print(" ackPayload sent ");
Serial.print(ackData[0]);
Serial.print(", ");
Serial.println(ackData[1]);
digitalWrite(5, HIGH);break;
newData = false;
if (newData == false) {
digitalWrite(5, LOW);break;
newData = true;
}
}
//================
void updateReplyData() {
ackData[0] -= 1;
ackData[1] -= 1;
if (ackData[0] < 100) {
ackData[0] = 109;
}
if (ackData[1] < -4009) {
ackData[1] = -4000;
}
radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}
Here is the area where I added the most code. It is the void Showdata.
void showData() {
if (newData == true) {
Serial.print("Data received ");
Serial.println(dataReceived);
Serial.print(" ackPayload sent ");
Serial.print(ackData[0]);
Serial.print(", ");
Serial.println(ackData[1]);
digitalWrite(5, HIGH);break;
newData = false;
if (newData == false) {
digitalWrite(5, LOW);break;
newData = true;
}
}
There is also an error message flashing that says
exit status 1
'updateReplyData' was not declared in this scope