PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

nrf51_client.pde 1.7KB

pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // nrf51_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_NRF51 class. RH_NRF51 class does not provide for addressing or
  5. // reliability, so you should only use RH_NRF51 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example nrf51_server.
  8. // Tested on RedBearLabs nRF51822 and BLE Nano kit, built with Arduino 1.6.4.
  9. // See http://redbearlab.com/getting-started-nrf51822/
  10. // for how to set up your Arduino build environment
  11. #include <RH_NRF51.h>
  12. // Singleton instance of the radio driver
  13. RH_NRF51 nrf51;
  14. void setup()
  15. {
  16. delay(1000); // Wait for serial port etc to be ready
  17. Serial.begin(9600);
  18. while (!Serial)
  19. ; // wait for serial port to connect.
  20. if (!nrf51.init())
  21. Serial.println("init failed");
  22. // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  23. if (!nrf51.setChannel(1))
  24. Serial.println("setChannel failed");
  25. if (!nrf51.setRF(RH_NRF51::DataRate2Mbps, RH_NRF51::TransmitPower0dBm))
  26. Serial.println("setRF failed");
  27. nrf51.printRegisters();
  28. }
  29. void loop()
  30. {
  31. Serial.println("Sending to nrf51_server");
  32. // Send a message to nrf51_server
  33. uint8_t data[] = "Hello World!";
  34. nrf51.send(data, sizeof(data));
  35. nrf51.waitPacketSent();
  36. // Now wait for a reply
  37. uint8_t buf[RH_NRF51_MAX_MESSAGE_LEN];
  38. uint8_t len = sizeof(buf);
  39. if (nrf51.waitAvailableTimeout(500))
  40. {
  41. // Should be a reply message for us now
  42. if (nrf51.recv(buf, &len))
  43. {
  44. Serial.print("got reply: ");
  45. Serial.println((char*)buf);
  46. }
  47. else
  48. {
  49. Serial.println("recv failed");
  50. }
  51. }
  52. else
  53. {
  54. Serial.println("No reply, is nrf51_server running?");
  55. }
  56. delay(400);
  57. }