Hello. I am trying to use nRF24L01 modules to send data from an arduino uno to an arduino nano, and get the nano to start carrying out a function. To do this, I am trying to say that if a variable equals a certain value, then the board should write something to the other board, but if it is not that value, then it should not send anything. However, I am having problems. I am trying to make it so that data is only sent once by changing the variable, but it is being printed on the receiver's serial monitor over and over. Does anybody know what might be wrong with my code?
Transmitter:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int num = 1;
int num2 = 2;
void setup() {
radio.begin();
Serial.begin(9600);
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
writing();
delay(1000);
}
void writing() {
if (num=1) {
radio.write(&num2, sizeof(num2));
num+=1;
}
else {
return;
}
}
Receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
int num = "";
radio.read(&num, sizeof(num));
if (num=1) {
Serial.println("Function");
}
else {
return;
}
}
}
Thanks in advance