I have a simple NRF24L01 transmitter and receiver, the transmitter has a button, and when I press the button I want it to turn on the a LED light that is connected to the receiver. I do not see my problem, I just cannot get this to work. Someone please review my code:
Transmitter:
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
RF24 radio(7, 8); //CE, CNS
const uint64_t pipe = 0xE8E8F0F0E1LL;
int buttonValue = 0;
int buttonPin = 3;
int msg[1];
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
}
void loop() {
if(buttonValue != 0){
// digitalWrite(ledPin, HIGH);
msg[0] = 1;
radio.write(msg, 1);
} else{
radio.write(msg, 0);
}
}```
Receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
RF24 radio(7,8); // CE, CNS
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int ledPin = 2;
void setup(){
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.setPALevel(RF24_PA_MAX);
radio.startListening();
}
void loop(){
if(radio.available()){
radio.read(msg, 1);
if(msg[0] == 1){
digitalWrite(ledPin, HIGH);
Serial.println(sizeof(msg));
} else{
digitalWrite(ledPin, LOW);
}
}
}