Hi Guy,
I just cant seem to do this and I need your help.
I am trying to turn a LED on using nrf24l01 module. I am using Arduino Duemilanove. If I can turn on LED I can use the code to turn on relay and eventually control lights in the house.
Following is my code, ofcourse I am trying to modify someone else's. Im not very good in C, just trying to learn using Arduino.
Thanks.
TX code :
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int i;
void setup(){
Serial.begin(9600);
Mirf.spi = &MirfHardwareSpi;
//Mirf.csnPin = 10; (This is optional to change the chip select pin)
//Mirf.cePin = 9; (This is optional to change the enable pin)
Mirf.init();
Mirf.setTADDR((byte *)"serv1");
Mirf.payload = 32;
Mirf.config();
Serial.println("Beginning ... ");
}
void loop(){
if (Serial.available()) {
i = Serial.read();
Serial.println(i);
Mirf.send((byte *) i);
delay (500);
}
}
RX code :
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int led = 4;
void setup(){
pinMode(led,OUTPUT);
Serial.begin(9600);
Mirf.spi = &MirfHardwareSpi;
//Mirf.csnPin = 10; (This is optional to change the chip select pin)
//Mirf.cePin = 9; (This is optional to change the enable pin)
Mirf.init();
Mirf.setTADDR((byte *)"serv1");
Mirf.payload = 32;
Mirf.config();
Serial.println("Beginning ... ");
}
void loop(){
byte data[0]; // or int data[32];
if(!Mirf.isSending() && Mirf.dataReady()){
Serial.println("Got packet");
Mirf.getData((byte *) &data);
Serial.println(data[0]);
if (data = 97) {
digitalWrite(led,HIGH);
}
else {
digitalWrite(led,LOW);
}
}
}