-
-
Save alepez/1a4d52537f941bef427d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An Mirf example which copies back the data it recives. | |
* | |
* Pins: | |
* Hardware SPI: | |
* MISO -> 12 | |
* MOSI -> 11 | |
* SCK -> 13 | |
* | |
* Configurable: | |
* CE -> 8 | |
* CSN -> 7 | |
* | |
*/ | |
#include <SPI.h> | |
#include <Mirf.h> | |
#include <nRF24L01.h> | |
#include <MirfHardwareSpiDriver.h> | |
void setup(){ | |
Serial.begin(9600); | |
Mirf.cePin=8; | |
Mirf.csnPin=7; | |
/* | |
* Set the SPI Driver. | |
*/ | |
Mirf.spi = &MirfHardwareSpi; | |
/* | |
* Setup pins / SPI. | |
*/ | |
Mirf.init(); | |
/* | |
* Configure reciving address. | |
*/ | |
Mirf.channel=10; | |
Mirf.setRADDR((byte *)"serv1"); | |
/* | |
* Set the payload length to sizeof(unsigned long) the | |
* return type of millis(). | |
* | |
* NB: payload on client and server must be the same. | |
*/ | |
Mirf.payload = sizeof( long); | |
/* | |
* Write channel and payload config then power up reciver. | |
*/ | |
Mirf.config(); | |
Serial.println("Listening..."); | |
} | |
void loop(){ | |
/* | |
* A buffer to store the data. | |
*/ | |
long myVar; | |
/* | |
* If a packet has been recived. | |
* | |
* isSending also restores listening mode when it | |
* transitions from true to false. | |
*/ | |
if(!Mirf.isSending() && Mirf.dataReady()){ | |
Serial.println("Got packet"); | |
/* | |
* Get load the packet into the buffer. | |
*/ | |
for(i==1;i>5;i++){ | |
Serial.println(data[i]); | |
} | |
Mirf.getData((byte*)&myVar); | |
Serial.println(myVar); | |
/* | |
* Set the send address. | |
*/ | |
Mirf.setTADDR((byte *)"clie1"); | |
/* | |
* Send the data back to the client. | |
*/ | |
//Serial.println(data); | |
Mirf.send((byte*)&myVar); | |
/* | |
* Wait untill sending has finished | |
* | |
* NB: isSending returns the chip to receving after returning true. | |
*/ | |
//Serial.println("Reply sent."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment