Advertisement
uas_arduino

Scooter Wireless Receiver

Mar 10th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. /* Required to use SPI */
  2. #include <SPI.h>
  3.  
  4. /* Libraries to talk to the NRF2401 */
  5. #include "nRF24L01.h"
  6. #include "RF24.h"
  7.  
  8. /* Sets up the RF24 libray a different way
  9.    for the Arduino Mega 2560 */
  10. #if defined(__AVR_ATmega2560__)
  11.   RF24 radio(53,48);
  12. #else
  13.   RF24 radio(9,10);
  14. #endif
  15.  
  16. /* Defines the structure of the data
  17.    that will be received. */
  18. struct data {
  19.   byte start;
  20.   byte left;
  21.   byte right;
  22.   byte finish;
  23. };
  24.  
  25. /* Give a friendly name to the struct */
  26. typedef struct data Packet;
  27.  
  28. /* Create an instance of the struct. */
  29. Packet pkt;
  30.  
  31. void setup(){
  32.   Serial.begin(115200);
  33.   Serial.println("Starting...");
  34.  
  35.   /* Sets up the NRF library */
  36.   radio.begin();
  37.   /* MUST BE OPPOSITE THE TRANSMITTER!!! */
  38.   radio.openReadingPipe(1,0xF0F0F0F0E1LL);
  39.   radio.openWritingPipe(0xF0F0F0F0D2LL);
  40.  
  41.   /* Set the radio up to listen */
  42.   radio.startListening();
  43. }
  44.  
  45. /* Dumps out the packet contents. */
  46. void printPacket(){
  47.   Serial.print(pkt.start,HEX);
  48.   Serial.print(" ");
  49.   Serial.print(pkt.left,HEX);
  50.   Serial.print(" ");
  51.   Serial.print(pkt.right,HEX);
  52.   Serial.print(" ");
  53.   Serial.println(pkt.finish,HEX);
  54. }
  55.  
  56.  
  57. void loop(){
  58.   /* Check to see if there is data available. */
  59.   if(radio.available()){
  60.     /* Read in one packet worth of data. */
  61.     radio.read(&pkt, sizeof(Packet));
  62.    
  63.     /* Print the contents to the Serial. */
  64.     printPacket();
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement