Please help with n24l01

I am trying to send the state of multiple buttons at the same time .Been trying to find a solution for days with no luck .

CODE FOR TX

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg0[1];
int msg1[1];
int msg2[1];
int msg3[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 2;
int SW2 = 3;
int SW3 = 4;
int SW4 = 5;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}

void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 1;
radio.write(msg, 1);}

if (digitalRead(SW2) == LOW){
msg1[0] = 2;
radio.write(msg1, 2);}

if (digitalRead(SW3) == LOW){
msg2[0] = 3;
radio.write(msg2, 3);}

if (digitalRead(SW4) == LOW){
msg3[0] = 4;
radio.write(msg3, 4);}
}

CODE FOR RX

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg0[1];
int msg1[1];
int msg2[1];
int msg3[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);}

void loop(void){
if (radio.available()){
bool done = false;
while (!done){

radio.read(msg0, 1);
Serial.println(msg0[0]);
if (msg0[0] == 1){delay(1);digitalWrite(LED1, LOW);}
else {digitalWrite(LED1, HIGH);}
delay(1);

radio.read(msg1, 2);
Serial.println(msg1[0]);
if (msg1[0] == 2){delay(1);digitalWrite(LED2, LOW);}
else {digitalWrite(LEd2, HIGH);}
delay(1);

radio.read(msg2, 3);
Serial.println(msg1[0]);
if (msg2[0] == 3){delay(1);digitalWrite(LED3, LOW);}
else {digitalWrite(LD#, HIGH);}
delay(1);

radio.read(msg3, 4);
Serial.println(msg1[0]);
if (msg3[0] == 4){delay(1);digitalWrite(LED4, LOW);}
else {digitalWrite(LED4, HIGH);}
delay(1);

}

You did not bother to search in this forum or you would have found Simple nRF24L01+ 2.4GHz transceiver demo

You did not bother to read Read this before posting a programming question ....

You did not bother to look at the examples of the library.

Your code is one of the most unsensible tries I have encoutered for quite a time.

I have seen the links you have posted . I just dont get it . I dont see where it is reading any states of pins and sending them I understand some . I have been struggling with this for a few days I know my coding sucks ,I am a hardware guy not software This is my first attempt to use radios .

I have been reading all I can on bitWrite and bitRead funtions Just cant figure out how to use it and send all states of the buttons at one time. Thats why I am reaching out for help. Any help would be help for

You can send 32 bytes at a time (read the datasheet) so why bother with bits?

One method would be something like:

struct Pack {
  bool fireButtonPressed;
  bool boosterOn;
  bool shieldsDown;
  bool brainMalfunction;
} packet;


  radio.write(&packet, sizeof(packet));

vitals817: I have seen the links you have posted . I just dont get it .

Both links point to spoon-feed material... :confused:

Like this ?
IF so how would it work on the rx side?
Thanks for the help

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int fireButtonPressed = 2;
int boosterOn = 3;
int shieldsDown = 4;
int brainMalfunction = 5;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}

void loop(void){

struct Pack {
bool fireButtonPressed;
bool boosterOn;
bool shieldsDown;
bool brainMalfunction;
} packet;

radio.write(&packet, sizeof(packet));}

Is the compiler happy? No warnings? Does it work?

(Hint: your code will flood the channel with junk, I see no reason to receive that)

There are examples in the link I posted, use them if you don't have a clue.

BTW Where are your code tags? (That is explained in the other link I posted...)

vitals817: Like this ? IF so how would it work on the rx side?

Make life easy for yourself (and us). Get the first example in my Simple nRF24L01+ Tutorial working without any changes.

When that is working reliably then start extending it to include your own data structure.

...R