Advertisement
_TEXNIK_

каналы

Jan 3rd, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <SPI.h>
  2. #include "nRF24L01.h"
  3. #include "RF24.h"
  4.  
  5. RF24 radio(9, 10); // инициализировать модуль на пинах 9 и 10 Для Уно
  6. //RF24 radio(9,53); // Для Меги
  7.  
  8. const uint8_t num_channels = 128;
  9. uint8_t values[num_channels];
  10. void setup() {
  11. Serial.begin(9600);
  12. printf_begin();
  13. radio.begin();
  14. radio.setAutoAck(false);
  15. radio.startListening();
  16.  
  17. radio.printDetails(); // Вот эта строка напечатает нам что-то, если все правильно соединили.
  18. delay(5000); // И посмотрим на это пять секунд.
  19.  
  20. radio.stopListening();
  21. int i = 0; // А это напечатает нам заголовки всех 127 каналов
  22. while ( i < num_channels ) {
  23. printf("%x", i >> 4);
  24. ++i;
  25. }
  26. printf("\n\r");
  27. i = 0;
  28. while ( i < num_channels ) {
  29. printf("%x", i & 0xf);
  30. ++i;
  31. }
  32. printf("\n\r");
  33. }
  34. const int num_reps = 100;
  35.  
  36. void loop(void)
  37. {
  38. memset(values, 0, sizeof(values));
  39. int rep_counter = num_reps;
  40. while (rep_counter--) {
  41. int i = num_channels;
  42. while (i--) {
  43. radio.setChannel(i);
  44. radio.startListening();
  45. delayMicroseconds(128);
  46. radio.stopListening();
  47. if ( radio.testCarrier() )
  48. ++values[i];
  49. }
  50. }
  51. int i = 0;
  52. while ( i < num_channels ) {
  53. printf("%x", min(0xf, values[i] & 0xf));
  54. ++i;
  55. }
  56. printf("\n\r");
  57. }
  58. int serial_putc( char c, FILE * ) {
  59. Serial.write( c );
  60. return c;
  61. }
  62.  
  63. void printf_begin(void) {
  64. fdevopen( &serial_putc, 0 );
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement