SHARE
TWEET

Untitled

dnanasim Mar 16th, 2015 243 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //receiver ---- MEGA
  2.  
  3. /* pin connections
  4.    ===============
  5.    
  6.    2  ->  CD
  7.    3  ->  DR
  8.    7  ->  CE
  9.    8  ->  PWR
  10.    9  ->  TXE
  11.   53  ->  CSN
  12.   51  ->  SI
  13.   50  ->  SO
  14.   52  ->  SCK
  15.  
  16. */
  17.  
  18.  
  19. #include <nRF905.h>
  20. #include <SPI.h>
  21.  
  22. #define RXADDR {0xFE, 0x4C, 0xA6, 0xE5}
  23. #define TXADDR {0x58, 0x6F, 0x2E, 0x10}
  24. #define TIMEOUT 1000
  25. int LED = 49;
  26.  
  27. void setup()
  28. {
  29.   nRF905_init();
  30.  
  31.   byte addr[] = RXADDR;
  32.   nRF905_setRXAddress(addr);
  33.   nRF905_setTransmitPower(NRF905_PWR_n10);
  34.   nRF905_setLowRxPower(NRF905_LOW_RX_ENABLE);
  35.   nRF905_receive();
  36.   pinMode(LED,OUTPUT);
  37.   pinMode(13,OUTPUT);
  38. }
  39.  
  40. void loop()
  41. {
  42.   char data[1] = {0};
  43.   nRF905_powerUp();
  44.   unsigned long startTime = millis();
  45.   byte addr[] = TXADDR;
  46.   nRF905_setTXAddress(addr);
  47.   nRF905_setData(data,sizeof(data));
  48.   while(!(nRF905_send()))
  49.   {
  50.     digitalWrite(13,HIGH);
  51.   };
  52.   nRF905_receive();
  53.  
  54.   int buflen = 1;
  55.   byte buffer [buflen];
  56.   boolean success;
  57.   unsigned long sendstarttime = millis();
  58.   while(1)
  59.   {
  60.     success = nRF905_getData(buffer,sizeof(buffer));
  61.     if(success)
  62.              break;
  63.     if(millis() - sendstarttime > TIMEOUT)
  64.              break;
  65.   }
  66.   nRF905_powerDown();
  67.   if(success)
  68.   {
  69.     if(buffer[0] == 1)
  70.           digitalWrite(LED,HIGH);
  71.     else
  72.          digitalWrite(LED,LOW);
  73.          
  74.     delay(1000);
  75.   }
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top