PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

59 Zeilen
1.4KB

  1. // rf24_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_RF24 class. RH_RF24 class does not provide for addressing or
  5. // reliability, so you should only use RH_RF24 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example rf24_server.
  8. // Tested on Anarduino Mini http://www.anarduino.com/mini/ with RFM24W and RFM26W
  9. #include <SPI.h>
  10. #include <RH_RF24.h>
  11. // Singleton instance of the radio driver
  12. RH_RF24 rf24;
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. if (!rf24.init())
  17. Serial.println("init failed");
  18. // Defaults after init are 434.0MHz, modulation GFSK_Rb5Fd10, power 0x10
  19. // if (!rf24.setFrequency(433.0))
  20. // Serial.println("setFrequency failed");
  21. }
  22. void loop()
  23. {
  24. Serial.println("Sending to rf24_server");
  25. // Send a message to rf24_server
  26. uint8_t data[] = "Hello World!";
  27. rf24.send(data, sizeof(data));
  28. rf24.waitPacketSent();
  29. // Now wait for a reply
  30. uint8_t buf[RH_RF24_MAX_MESSAGE_LEN];
  31. uint8_t len = sizeof(buf);
  32. if (rf24.waitAvailableTimeout(500))
  33. {
  34. // Should be a reply message for us now
  35. if (rf24.recv(buf, &len))
  36. {
  37. Serial.print("got reply: ");
  38. Serial.println((char*)buf);
  39. }
  40. else
  41. {
  42. Serial.println("recv failed");
  43. }
  44. }
  45. else
  46. {
  47. Serial.println("No reply, is rf24_server running?");
  48. }
  49. delay(400);
  50. }