Guest User

Untitled

a guest
Aug 2nd, 2015
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <nRF905.h>
  2. #include <SPI.h>
  3.  
  4. void setup()
  5. {
  6.     // Start up
  7.     nRF905_init();
  8.  
  9.     // Put into receive mode
  10.     nRF905_receive();
  11.  
  12.     Serial.begin(9600);
  13.  
  14.     Serial.println(F("Client started"));
  15. }
  16.  
  17. void loop()
  18. {
  19.     char data[NRF905_MAX_PAYLOAD] = {0};
  20.  
  21.     // Load analog values into payload
  22.     for(byte i=0;i<5;i++)
  23.     {
  24.         int val = analogRead(i);
  25.         data[i * 2] = val;
  26.         data[(i * 2) + 1] = val>>8;
  27.     }
  28.  
  29.     // Set payload data
  30.     nRF905_setData(data, sizeof(data));
  31.  
  32.     // Send payload (send fails if other transmissions are going on, keep trying until success)
  33.     while(!nRF905_send());
  34.  
  35.     // Put into receive mode
  36.     nRF905_receive();
  37.  
  38.     // Wait here until 250ms has passed
  39.     unsigned long startTime = millis();
  40.     while(millis() - startTime < 250)
  41.         nRF905_getData(NULL, 0); // Clear any received data
  42. }
RAW Paste Data