Advertisement
Guest User

Přijímač

a guest
Sep 14th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /*
  2. * Arduino Wireless Communication Tutorial
  3. * Example 1 - Receiver Code
  4. *
  5. * by Dejan Nedelkovski, www.HowToMechatronics.com
  6. *
  7. * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
  8. */
  9. #include <Wire.h>
  10. #include "RTClib.h"
  11. RTC_DS3231 rtc;
  12. #include <SPI.h>
  13. #include <nRF24L01.h>
  14. #include <RF24.h>
  15. RF24 radio(48,49); // CE, CSN
  16. const byte addresses[][6] = {"00001", "00002"};
  17. int prijato=0;
  18.  
  19. int teplota;
  20. int vlhkost;
  21.  
  22. void setup() {
  23. Serial.begin(9600);
  24. rtc.begin();
  25. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  26. radio.begin();
  27. radio.openReadingPipe(1, addresses[1]);
  28. radio.setPALevel(RF24_PA_MAX);
  29. radio.startListening();
  30. }
  31. void loop() {
  32.  
  33. if (radio.available())
  34. {
  35. radio.read(&prijato, sizeof(prijato));
  36. Serial.print("prijata data: ");
  37. Serial.println(prijato);
  38.  
  39. DateTime now = rtc.now();
  40. Serial.print(now.hour(), DEC);
  41. Serial.print(':');
  42. Serial.print(now.minute(), DEC);
  43. Serial.print(':');
  44. Serial.print(now.second(), DEC);
  45. Serial.println(" ");
  46.  
  47. switch(prijato)
  48. {
  49. case 1010: //teplota
  50. radio.read(&teplota, sizeof(teplota));
  51. Serial.print("teplota: ");
  52. Serial.print(teplota);
  53. Serial.println("°C");
  54. break;
  55.  
  56. case 1011: //vlhkost
  57. radio.read(&vlhkost, sizeof(vlhkost));
  58. Serial.print("vlhkost: ");
  59. Serial.print(vlhkost);
  60. Serial.println("%");
  61. break;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement