Здравствуйте.
Не разобралась в работе скетча сканера частот
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
const uint8_t CE = 9;
const uint8_t CS = 10;
const uint8_t num_channels = 128; //Число каналов
uint8_t values[num_channels]; //Массив значений
RF24 radio(9, 10);
void setup() {
Serial.begin(57600);
radio.begin();
radio.setAutoAck(false);
}
void loop() {
memset(values, 0, num_channels);
for (uint8_t i = 0; i < 10; i++) {
for (uint8_t k = 0; k < num_channels; k++) {
radio.setChannel(k); //Выбираем канал
radio.startListening(); //Начинаем прослушивать
delayMicroseconds(128); //Ждём
radio.stopListening(); //Останавливаем прослушивание
if (radio.testCarrier()) values[k]++; //Если есть сигнал, прибавляем значение
//if (radio.testRPD()) values[k]++;
}
}
for (uint8_t k = 0; k < num_channels; k++) {
Serial.print(values[k]);
}
Serial.println("");
}
Получаю
00000000000000000000000000000000000000011111111111110000000000000000000000000000000000000000000000000000000000000000000000000000
00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000010000000000000000000001111110000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000011111111110000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000001111111111111000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000021000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000001111111111111100000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000011110100000000000000000000000000000000000000000000000000000000000000000000000000000000000
А во “взрослых скетчах” значения стабильные
00000000000000000000000000100000000000099ab97896878a8bba78c642010000000000000000100000000000000000000000000000000000000000000000
0000000000000000000000000010000000011016557a8888999adaba369d60021000000000000000200000000000000000000000000000000000000000000000
0100000000000000000000000010000000000007bb8abb9cabbadeed467972100000000000000000100000000000000000000000000000000000000000000000
000000000000000000000000012000000000002a99a88889898a88c777ba51000000000000000000100000000000000000000000000000000000000000000000
000000000000000000000000000000000000001c978ba8a99799bcbb77cb51011000000000000000200000000000000000000000000000000000000000000000
Спойлер
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(9,10); // Для Уно
//RF24 radio(9,53);// Для Меги
const uint8_t num_channels = 128;
uint8_t values[num_channels];
void setup(void)
{
Serial.begin(57600);
printf_begin();
radio.begin();
radio.setAutoAck(false);
radio.startListening();
radio.printDetails(); // Вот эта строка напечатает нам что-то, если все правильно соединили.
delay(5000); // И посмотрим на это пять секунд.
radio.stopListening();
int i = 0; // А это напечатает нам заголовки всех 127 каналов
while ( i < num_channels ) {
printf("%x",i>>4);
++i;
}
printf("\n\r");
i = 0;
while ( i < num_channels ) {
printf("%x",i&0xf);
++i;
}
printf("\n\r");
}
const int num_reps = 100;
void loop(void)
{
memset(values,0,sizeof(values));
int rep_counter = num_reps;
while (rep_counter--) {
int i = num_channels;
while (i--) {
radio.setChannel(i);
radio.startListening();
delayMicroseconds(128);
radio.stopListening();
if ( radio.testCarrier() )
++values[i];
}
}
int i = 0;
while ( i < num_channels ) {
printf("%x",min(0xf,values[i]&0xf));
++i;
}
printf("\n\r");
}
int serial_putc( char c, FILE * ) {
Serial.write( c );
return c;
}
void printf_begin(void) {
fdevopen( &serial_putc, 0 );
}