Hi
I'm pretty new to all this and am working with a nRF2401. The code I am using is below it receives what it's suppose to and turns an LED on if it receives the correct number. If I upload it with it sending "c" and then in ASCII it's 99, it works out the LED comes on. Then I upload the transmitting board to send an "o" and the receiving board continues to receive 99 until I reset the serial monitor on the receiving board... what am I doing wrong? How can I get it to receive the new transmission? is there a way to like tell it to wipe it's memory and start over each time it loops or something?
Thanks,
Zyan
Receiving board
int state = 0;
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
void setup(){
Serial.begin(9600);
pinMode(4, OUTPUT);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.config();
Mirf.payload = sizeof(int);
Serial.println("Listening...");
}
void loop(){
byte data[Mirf.payload];
if(Mirf.dataReady()){
do{
Serial.println("Got packet");
int data;
Mirf.getData((byte *) &data);
Serial.println(data);
state = data;
if (state == 99){
digitalWrite(4, HIGH);
}
else
{
digitalWrite(4, LOW);
}
}while(!Mirf.rxFifoEmpty());
}
}
Transmitting Board
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
void setup(){
Serial.begin(9600);
Mirf.cePin = 7;
Mirf.csnPin = 8;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.payload = sizeof(int);
Mirf.config();
Serial.println("Beginning ... ");
}
void loop(){
Mirf.setTADDR((byte *)"serv1");
Mirf.send((byte *)"c");
while(Mirf.isSending()){
}
Serial.println("Finished sending");
delay(10);
}