Advertisement
rozman50

Arduino transmitter - string to array - important!

Feb 17th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. /*
  2. * Arduino Wireless Communication Tutorial
  3. * Example 1 - Transmitter Code
  4. *
  5. * by Dejan Nedelkovski, www.HowToMechatronics.com
  6. *
  7. * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
  8. */
  9. #include <SPI.h>
  10. #include <nRF24L01.h>
  11. #include <RF24.h>
  12.  
  13.  
  14. RF24 radio(7, 8); // CE, CSN
  15.  
  16. const byte addresses[][6] = {"00001", "00002"};
  17. int i = 0;
  18.  
  19. void setup() {
  20. radio.begin();
  21. radio.openWritingPipe(addresses[1]);
  22. radio.openReadingPipe(1, addresses[0]);
  23. radio.setPALevel(RF24_PA_MIN);
  24. Serial.begin(9600);
  25. }
  26. /*
  27. void loop() {
  28. radio.startListening();
  29.  
  30. if(radio.available()) {
  31. while(radio.available()) {
  32. char text[32] = "";
  33. radio.read(&text, sizeof(text));
  34. Serial.println(text):
  35.  
  36.  
  37. }
  38.  
  39. radio.stopListening();
  40.  
  41.  
  42. String besedilo = "Lorem.";
  43. char dajbek[32];
  44.  
  45. besedilo.toCharArray(dajbek, 32);
  46. radio.write(&dajbek, sizeof(dajbek));
  47. }
  48. }
  49. */
  50.  
  51. void loop() {
  52. char text[32];
  53.  
  54. String besedilo = "Lorem ipsum";
  55.  
  56. radio.stopListening();
  57. // besedilo.concat(i);
  58. // Serial.println(besedilo);
  59. besedilo.toCharArray(text, 32);
  60. radio.write(&text, sizeof(text));
  61.  
  62. // memset(text, 0, sizeof(text));
  63.  
  64. delay(5);
  65. radio.startListening();
  66.  
  67. while (!radio.available());
  68.  
  69. Serial.println("Zabase se");
  70.  
  71. char preberi[32];
  72. radio.read(&preberi, sizeof(preberi));
  73. Serial.println(preberi);
  74.  
  75. memset(preberi, 0, sizeof(preberi));
  76. i++;
  77.  
  78. Serial.println(i);
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement