PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

4 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // mrf89_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  4. // with the RH_MRF89 class. RH_MRF89 class does not provide for addressing or
  5. // reliability, so you should only use RH_MRF89 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example mrf89_client
  8. // Tested with Teensy and MRF89XAM9A
  9. #include <SPI.h>
  10. #include <RH_MRF89.h>
  11. // Singleton instance of the radio driver
  12. RH_MRF89 mrf89;
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. while (!Serial)
  17. ; // wait for serial port to connect. Needed for native USB
  18. if (!mrf89.init())
  19. Serial.println("init failed");
  20. // Default after init is 1dBm, 915.4MHz, FSK_Rb20Fd40
  21. // But you can change that if you want:
  22. // mrf89.setTxPower(RH_MRF89_TXOPVAL_M8DBM); // Min power -8dBm
  23. // mrf89.setTxPower(RH_MRF89_TXOPVAL_13DBM); // Max power 13dBm
  24. // if (!mrf89.setFrequency(920.0))
  25. // Serial.println("setFrequency failed");
  26. // if (!mrf89.setModemConfig(RH_MRF89::FSK_Rb200Fd200)) // Fastest
  27. // Serial.println("setModemConfig failed");
  28. }
  29. void loop()
  30. {
  31. if (mrf89.available())
  32. {
  33. // Should be a message for us now
  34. uint8_t buf[RH_MRF89_MAX_MESSAGE_LEN];
  35. uint8_t len = sizeof(buf);
  36. if (mrf89.recv(buf, &len))
  37. {
  38. // RH_MRF89::printBuffer("request: ", buf, len);
  39. Serial.print("got request: ");
  40. Serial.println((char*)buf);
  41. // Serial.print("RSSI: ");
  42. // Serial.println(mrf89.lastRssi(), DEC);
  43. // Send a reply
  44. uint8_t data[] = "And hello back to you";
  45. mrf89.send(data, sizeof(data));
  46. mrf89.waitPacketSent();
  47. Serial.println("Sent a reply");
  48. }
  49. else
  50. {
  51. Serial.println("recv failed");
  52. }
  53. }
  54. // delay(10000);
  55. // mrf89.printRegisters();
  56. // while (1);
  57. }