Hello Everyone.
I need some help how to use this code below with 2 nodes or more.
The code is basically to controll 2 led using 2 button using nRF24L01.
Now I want to control LEDs on 2 nodes (2 LEDs for each Nodes) but I'm new in arduino.
my question is how to addressing the code for 2 Nodes or more? Here is the basic code :
TX :
//Programa : Teste NRF24L01 - Emissor - Botoes
//Autor : Adilson Thomsen
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int data[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE14BC8F482LL;
int button1 = 2;
int button2 = 3;
int button3 = 4;
int button4 = 5;
void setup()
{
pinMode(2, INPUT);
digitalWrite(2,HIGH);
pinMode(3, INPUT);
digitalWrite(3,HIGH);
pinMode(4, INPUT);
digitalWrite(4,HIGH);
pinMode(5, INPUT);
digitalWrite(5,HIGH);
Serial.begin(57600);
Serial.println(" ");
radio.begin();
radio.openWritingPipe(pipe);
}
void loop()
{
if (digitalRead(button1) == LOW)
{
Serial.println(" ");
data[0] = 1;
radio.write(data, 1);
}
if (digitalRead(button2) == LOW)
{
Serial.println(" ");
data[0] = 2;
radio.write(data, 1);
}
if (digitalRead(button3) == LOW)
{
Serial.println(" ");
data[0] = 3;
radio.write(data, 1);
}
if (digitalRead(button4) == LOW)
{
Serial.println(" ");
data[0] = 4;
radio.write(data, 1);
}
}
RX :
//Programa : Teste NRF24L01 - Emissor - Botoes
//Autor : Adilson Thomsen
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int data[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE14BC8F482LL;
int button1 = 2;
int button2 = 3;
int button3 = 4;
int button4 = 5;
void setup()
{
pinMode(2, INPUT);
digitalWrite(2,HIGH);
pinMode(3, INPUT);
digitalWrite(3,HIGH);
pinMode(4, INPUT);
digitalWrite(4,HIGH);
pinMode(5, INPUT);
digitalWrite(5,HIGH);
Serial.begin(57600);
Serial.println(" ");
radio.begin();
radio.openWritingPipe(pipe);
}
void loop()
{
if (digitalRead(button1) == LOW)
{
Serial.println(" ");
data[0] = 1;
radio.write(data, 1);
}
if (digitalRead(button2) == LOW)
{
Serial.println(" ");
data[0] = 2;
radio.write(data, 1);
}
if (digitalRead(button3) == LOW)
{
Serial.println(" ");
data[0] = 3;
radio.write(data, 1);
}
if (digitalRead(button4) == LOW)
{
Serial.println(" ");
data[0] = 4;
radio.write(data, 1);
}
}
Or maybe someone have another better suggestions? thank you before.