Guest User

Untitled

a guest
Feb 9th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <RF24.h>
  2. #include <RF24_config.h>
  3. #include <SPI.h>
  4. #include "printf.h"
  5. bool waitForAck = false;
  6. RF24E radio(9, 53);
  7.  
  8. void setup()
  9. {
  10. Serial.begin(115200);
  11. delay(250);
  12. radio.begin();
  13. radio.setChannel(0x57);
  14. radio.setPALevel(RF24_PA_LOW);
  15. radio.enableAckPayload();
  16. radio.openReadingPipe(1, pipe01_);
  17. radio.openWritingPipe(pipe02_);
  18. radio.enableDynamicPayloads();
  19. radio.startListening();
  20. }
  21.  
  22. void loop()
  23. {
  24. if (radio.available())
  25. {
  26. char newMessage[33];
  27. memset(newMessage, 0, sizeof(byte) * 33);
  28. while (available())
  29. {radio.read(newMessage, 32);}
  30.  
  31. Serial.println("newMessage: " + String((const char*)newMessage));
  32. delay(1000);
  33. radio.stopListening();
  34.  
  35. char response[32] = "1234567890qwertyuiopasdfghjklzxc";
  36. radio.write(response, 32);
  37. unsigned long ack = 0;
  38. if (radio.isAckPayloadAvailable())
  39. {
  40. radio.read(&ack, sizeof(ack));
  41. Serial.println("ack: " + String(ack));
  42. }
  43. radio.startListening();
  44. }
  45. }
  46.  
  47. #include <RF24.h>
  48. #include <RF24_config.h>
  49. #include <SPI.h>
  50. #include "printf.h"
  51. bool waitForAck = false;
  52. RF24E radio(9, 53);
  53.  
  54. void setup()
  55. {
  56. Serial.begin(115200);
  57. delay(250);
  58. radio.begin();
  59. radio.setChannel(0x57);
  60. radio.setPALevel(RF24_PA_LOW);
  61. radio.enableAckPayload();
  62. radio.openReadingPipe(2, pipe02_);
  63. radio.openWritingPipe(pipe01_);
  64. radio.enableDynamicPayloads();
  65. radio.stopListening();
  66.  
  67. char message[32] = "qwertyuiopasdfghjklzxc1234567890";
  68. radio.write(message, 32);
  69.  
  70. radio.startListening();
  71. }
  72.  
  73. void loop()
  74. {
  75. if (radio.available())
  76. {
  77. char respMessage[33];
  78. memset(respMessage, 0, sizeof(byte) * 33);
  79. while (available())
  80. {radio.read(respMessage, 32);}
  81.  
  82. Serial.println("respMessage: " + String((const char*)respMessage));
  83. }
  84. }
Add Comment
Please, Sign In to add comment