Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Required to use SPI */
- #include <SPI.h>
- /* Libraries to talk to the NRF2401 */
- #include "nRF24L01.h"
- #include "RF24.h"
- /* Sets up the RF24 libray a different way
- for the Arduino Mega 2560 */
- #if defined(__AVR_ATmega2560__)
- RF24 radio(53,48);
- #else
- RF24 radio(9,10);
- #endif
- /* Defines the structure of the data
- that will be received. */
- struct data {
- byte start;
- byte left;
- byte right;
- byte finish;
- };
- /* Give a friendly name to the struct */
- typedef struct data Packet;
- /* Create an instance of the struct. */
- Packet pkt;
- void setup(){
- Serial.begin(115200);
- Serial.println("Starting...");
- /* Sets up the NRF library */
- radio.begin();
- /* MUST BE OPPOSITE THE TRANSMITTER!!! */
- radio.openReadingPipe(1,0xF0F0F0F0E1LL);
- radio.openWritingPipe(0xF0F0F0F0D2LL);
- /* Set the radio up to listen */
- radio.startListening();
- }
- /* Dumps out the packet contents. */
- void printPacket(){
- Serial.print(pkt.start,HEX);
- Serial.print(" ");
- Serial.print(pkt.left,HEX);
- Serial.print(" ");
- Serial.print(pkt.right,HEX);
- Serial.print(" ");
- Serial.println(pkt.finish,HEX);
- }
- void loop(){
- /* Check to see if there is data available. */
- if(radio.available()){
- /* Read in one packet worth of data. */
- radio.read(&pkt, sizeof(Packet));
- /* Print the contents to the Serial. */
- printPacket();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement