hi all :).. this is my code of c for transmiting data 0 and 1 and want to blink the LED on and off by recving that 0 and 0....but this code cannot work for me....i want to read the port of arduino uno and sent that binary to the reciver end to blink the led on and when the port goes to low the led getting offf....
//////// transmitter code////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define x 7
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int data[2];
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop()
{
if(digitalRead(x) == HIGH)
{
radio.stopListening(); // must stop listening before you open a writing pipe
radio.openWritingPipe(pipe);
data[0] = 1;
//joystick[1] = analogRead(x);
radio.write( data, sizeof(data) );
delay(200);
}
else
{
radio.stopListening(); // must stop listening before you open a writing pipe
radio.openWritingPipe(pipe);
data[1]= 0;
radio.write( data, sizeof(data) );
delay(200);
}
}
/////////////// reciver code////////////
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int data[2];
int led =7;
void setup()
{
Serial.begin(9600);
pinMode (led, OUTPUT);
delay(1000);
//Serial.println(“Nrf24L01 Receiver Starting”);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}
void loop()
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
done = radio.read( data, sizeof(data) );
if (done== HIGH)
{
digitalWrite (led, HIGH);
delay(1000);
}
if (done== LOW)
{
digitalWrite (led, LOW);
delay(1000);
}
}
}
}
//else
//digitalWrite (led, LOW);
//delay(1000);
//Serial.println(“No radio available”);
//}