Advertisement
Guest User

test

a guest
Dec 7th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4. RF24 radio(9, 10);
  5. String NI = String(180, BIN);
  6. String preambula = "10101010";
  7. int nrsek = 0;
  8. int nrwezla = 4;
  9. int msg;
  10.  
  11. const uint64_t pipes[2] = {0xF0F0F0F0E2LL, 0xF0F0F0F0D3LL};
  12. void setup() {
  13. // put your setup code here, to run once:
  14. Serial.begin(9600);
  15. radio.begin();
  16. radio.setRetries(15, 15);
  17. //radio.openWritingPipe(pipes[1]); // Open pipes for transmitter
  18.  
  19. }
  20.  
  21. int x = 0;
  22. void loop() {
  23. // put your main code here, to run repeatedly:
  24. if(x == 0)
  25. {
  26. x = Serial.read();
  27. Serial.println(x);
  28. delay(1000);
  29. }
  30. else if(x==49)
  31. {
  32. radio.openReadingPipe(1, pipes[0]);
  33. radio.openWritingPipe(pipes[1]);
  34. radio.startListening();
  35.  
  36. const char text[] = "jakis inny tekst";
  37. radio.write(&text, sizeof(text));
  38. //Serial.println(text);
  39. delay(1000);
  40. }
  41. else if(x==50)
  42. {
  43. radio.openReadingPipe(1, pipes[1]);
  44. radio.openWritingPipe(pipes[0]);
  45. radio.startListening();
  46. radio.read(msg, 16);
  47. Serial.println(msg);
  48. }
  49. else
  50. {
  51. x=0;
  52. }
  53.  
  54. //testobecnosci();
  55. }
  56.  
  57. void testobecnosci()
  58. {
  59. for(int i=1;i<=255;i++)
  60. {
  61. if(i == nrwezla)
  62. {
  63. continue;
  64. }
  65. String text = preambula;
  66. text+=NI;
  67. String SI = String(i, BIN);
  68. while(SI.length()!=8)
  69. {
  70. SI="0"+SI;
  71. }
  72. text+=SI;
  73. text+="00000001";
  74. String SN = String(nrsek, BIN);
  75. while(SN.length()!=8)
  76. {
  77. SN="0"+SN;
  78. }
  79. text+=SN;
  80. for(int j=0;j<128;j++)
  81. {
  82. text+="0";
  83. }
  84. for(int j=0;j<8;j++)
  85. {
  86. text+="0";
  87. }
  88. Serial.println(text);
  89. nrsek++;
  90. if(nrsek>255)
  91. {
  92. nrsek = 0;
  93. }
  94. radio.write(&text, sizeof(text));
  95. delay(100);
  96. }
  97. }
  98.  
  99.  
  100. void obecnosc()
  101. {
  102. radio.stopListening();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement