Guest User

Untitled

a guest
Jun 26th, 2014
219
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.     int val = analogRead(sensor);
  20.  
  21.     char data[NRF905_MAX_PAYLOAD] = {0};
  22.     memcpy(data, &val, sizeof(val));
  23.  
  24.     // Set payload data
  25.     nRF905_setData(data, sizeof(data));
  26.  
  27.     // Send payload (send fails if other transmissions are going on, keep trying until success)
  28.     while(!nRF905_send());
  29.  
  30.     // Put into receive mode
  31.     nRF905_receive();
  32.  
  33.     // Wait here until 250ms has passed
  34.     unsigned long startTime = millis();
  35.     while(millis() - startTime < 250)
  36.         nRF905_getData(NULL, 0);
  37. }
RAW Paste Data