//Code für die Basis Node 00 (Master)
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#define led1 3
#define led2 4
int Eingang;
RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of this node in Octal format ( 04,031, etc)
void setup() {
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Eingang = 0;
}
void loop()
{
Eingangsabfrage();
if (Eingang == 100)
{
digitalWrite(led1, HIGH);
}
if (Eingang == 200)
{
digitalWrite(led1, LOW);
}
if (Eingang == 300)
{
digitalWrite(led2, HIGH);
}
if (Eingang == 400)
{
digitalWrite(led2, LOW);
}
}
void Eingangsabfrage()
{
network.update();
while ( network.available() )
{ // Is there any incoming data?
RF24NetworkHeader header;
unsigned long incomingData;
network.read(header, &incomingData, sizeof(incomingData)); // Read the incoming data
Eingang = incomingData;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------
//Code für Node 01
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
int Start = 100;
int Stopp = 200;
const int Taster1 = 3; //LED1 bei Master ein
const int Taster2 = 4; //LED1 bei Master aus
RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 01; // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
void setup() {
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
pinMode(Taster1,INPUT);
pinMode(Taster2,INPUT);
}
void loop() {
network.update();
//===== Sending =====//
if (digitalRead(Taster1)==HIGH) { // If it's time to send a data, send it! //LED1 bei Master ein
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &Start, sizeof(Start)); // Send the data
delay(300);
}
if (digitalRead(Taster2)==HIGH) { // If it's time to send a data, send it! //LED1 bei Master aus
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &Stopp, sizeof(Stopp)); // Send the data
delay(300);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------
//Code für Node 011
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
int Start = 300;
int Stopp = 400;
const int Taster1 = 3; //LED2 bei Master ein
const int Taster2 = 4; //LED2 bei Master aus
RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 011; // Address of our node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
void setup() {
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
pinMode(Taster1,INPUT);
pinMode(Taster2,INPUT);
}
void loop() {
network.update();
//===== Sending =====//
if (digitalRead(Taster1)==HIGH) { // If it's time to send a data, send it! //LED1 bei Master ein
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &Start, sizeof(Start)); // Send the data
delay(300);
}
if (digitalRead(Taster2)==HIGH) { // If it's time to send a data, send it! //LED1 bei Master aus
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &Stopp, sizeof(Stopp)); // Send the data
delay(300);
}
}