Created
March 14, 2025 18:35
-
-
Save zr0n/0898175153392233a593903460d0c7c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <nRF24L01.h> | |
#include <RF24.h> | |
#define CE_PIN_1 7 // Primeiro rádio | |
#define CSN_PIN_1 8 | |
#define CE_PIN_2 9 // Segundo rádio | |
#define CSN_PIN_2 10 | |
const uint8_t BLUETOOTH_CHANNELS[] = {32, 34, 46, 48, 50, 52, 0, 1, 2, 4, 6, 8, 22, 24, 26, 28, 30, 74, 76, 78, 80}; | |
RF24 radio1(CE_PIN_1, CSN_PIN_1); // Instância do primeiro rádio | |
RF24 radio2(CE_PIN_2, CSN_PIN_2); // Instância do segundo rádio | |
uint8_t noise_data[32]; // Buffer único para ambos (pode usar buffers separados) | |
//--------------------------------------- | |
void setup() { | |
Serial.begin(115200); | |
// Geração de ruído | |
randomSeed(analogRead(0)); | |
for (uint8_t i = 0; i < 32; i++) { | |
noise_data[i] = random(256); | |
} | |
// Inicialização dos rádios | |
if (!radio1.begin() || !radio2.begin()) { | |
Serial.println("Falha em um dos módulos!"); | |
while(1); | |
} | |
// Configuração do Rádio 1 | |
radio1.setDataRate(RF24_2MBPS); | |
radio1.setPALevel(RF24_PA_MAX); | |
radio1.setAutoAck(false); | |
radio1.disableCRC(); | |
radio1.stopListening(); | |
// Configuração do Rádio 2 (replicar configurações) | |
radio2.setDataRate(RF24_2MBPS); | |
radio2.setPALevel(RF24_PA_MAX); | |
radio2.setAutoAck(false); | |
radio2.disableCRC(); | |
radio2.stopListening(); | |
Serial.println("Ambos rádios OK!"); | |
} | |
//--------------------------------------- | |
void loop() { | |
for (uint8_t channel : BLUETOOTH_CHANNELS) { | |
// Sincroniza ambos rádios no mesmo canal | |
radio1.setChannel(channel); | |
radio2.setChannel(channel); | |
// Dispara transmissões simultâneas | |
radio1.startFastWrite(noise_data, sizeof(noise_data), true); | |
radio2.startFastWrite(noise_data, sizeof(noise_data), true); | |
delayMicroseconds(100); // Ajuste fino conforme necessidade | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment