Go Down

Topic: Replace switch with software blinker (Read 264 times) previous topic - next topic

hugovic

Hello,
I´m beginner, so, be patient please :D

I have wireless communication with NRF24L01. It´s basic scheme. If I push switch on TX, LED diode flash. All what I need is make blinker from my TX (replace switch with software blinker and send it to RX).

I know, it´s basic code, but I can´t find the right way :/

Code for TX:

Code: [Select]
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

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

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

Grumpy_Mike

As we haven't got a clue what your RX code is, how can we know what code the TX has to send to activate this function.

hugovic

Sorry, this is RX code


Code: [Select]

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

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

void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println("No radio available");}}

Grumpy_Mike

Do you want too have the flashing all the time once you have sent a command?
Do you want to send another command to stop the flashing?

If so you need to take the RX code and use it to set and clear a Boolean variable and not use the while ! done loop. Then at the end of the loop function add code that blinks the LED or not depending on the state of this variable.

Use the millis timer to tell you when to turn the LED on or off, not the delay function.

Go Up