Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <nRF905.h>
- #include <SPI.h>
- void setup()
- {
- // Start up
- nRF905_init();
- // Put into receive mode
- nRF905_receive();
- Serial.begin(9600);
- Serial.println(F("Server started"));
- }
- void loop()
- {
- Serial.println(F("Waiting for data..."));
- // Make buffer for data
- byte buffer[NRF905_MAX_PAYLOAD];
- // Wait for data
- while(!nRF905_getData(buffer, sizeof(buffer)));
- float temp_c;
- float temp_f;
- float humidity;
- // Get data from buffer
- memcpy(&temp_c, buffer, sizeof(float));
- memcpy(&temp_f, buffer + sizeof(float), sizeof(float));
- memcpy(&humidity, buffer + (sizeof(float) * 2), sizeof(float));
- // Print the values to the serial port
- Serial.print("Temperature: ");
- Serial.print(temp_c, DEC);
- Serial.print("C / ");
- Serial.print(temp_f, DEC);
- Serial.print("F. Humidity: ");
- Serial.print(humidity);
- Serial.println("%");
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement