I am using RF24 modules with my two Arduinos Leonardo with the RF24 library. My goal is to be able to press a button on the first Arduino which will light up an LED on the second Arduino, and be able to press a button on the second Arduino to light up an LED on the first Arduino. I was easily able to figure this out as a one-way transmission with the first Arduino only transmitting and the second only receiving, but I am unable to make it a two-way transmission, where each Arduino can transmit and receive at the same time.
This is my code so far:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
const uint64_t pipe2 = 0xF0F0F0F0AA;
void setup(void){
Serial.begin(57600);
pinMode(A0, INPUT);
radio.begin();
radio.openWritingPipe(pipe);
radio.openReadingPipe(1,pipe2);
}
void loop(void){
int charToSend[1];
charToSend[0] = digitalRead(A0);
if (!radio.write(charToSend,1)) {Serial.println('didn\'t send');}
radio.startListening();
if (radio.available()){
bool done = false;
done = radio.read(msg, 1);
Serial.println(msg[0]);
digitalWrite(13, msg[0]);
}
radio.stopListening();
radio.powerDown();
delay(10);
radio.powerUp();
}
But the radio.write() is returning false and therefore not sending.