Guest User

Untitled

a guest
Nov 7th, 2014
101
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("Server started"));
  15. }
  16.  
  17. void loop()
  18. {
  19.     Serial.println(F("Waiting for data..."));
  20.  
  21.     // Make buffer for data
  22.     byte buffer[NRF905_MAX_PAYLOAD];
  23.  
  24.     // Wait for data
  25.     while(!nRF905_getData(buffer, sizeof(buffer)));
  26.  
  27.     float temp_c;
  28.     float temp_f;
  29.     float humidity;
  30.    
  31.     // Get data from buffer
  32.     memcpy(&temp_c, buffer, sizeof(float));
  33.     memcpy(&temp_f, buffer + sizeof(float), sizeof(float));
  34.     memcpy(&humidity, buffer + (sizeof(float) * 2), sizeof(float));
  35.  
  36.     // Print the values to the serial port
  37.     Serial.print("Temperature: ");
  38.     Serial.print(temp_c, DEC);
  39.     Serial.print("C / ");
  40.     Serial.print(temp_f, DEC);
  41.     Serial.print("F. Humidity: ");
  42.     Serial.print(humidity);
  43.     Serial.println("%");
  44.    
  45.     Serial.println();
  46. }
RAW Paste Data