-
Notifications
You must be signed in to change notification settings - Fork 0
/
Freq_Hop_Entropy.ino
43 lines (32 loc) · 1.3 KB
/
Freq_Hop_Entropy.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Write a simple arduino Frequency Hopping Algorithm which uses the entropy library written by Walter Anderson (entropy.h, entropy.cpp).
#include <Entropy.h> // Include the entropy library
#define HOP_MIN 400 // Define the minimum frequency (in MHz) for hopping
#define HOP_MAX 520 // Define the maximum frequency (in MHz) for hopping
void setup() {
// Initialize serial communications
Serial.begin(9600);
// Initialize entropy library
Entropy.initialize();
// Assume we have a function to set the radio frequency
// This will be radio specific and not covered by the Arduino standard library
setRadioFrequency(getRandomFrequency());
}
void loop() {
// Assume we have some condition for when to hop frequencies
// Here we just wait for a second
delay(1000);
// Set the new frequency
setRadioFrequency(getRandomFrequency());
}
float getRandomFrequency() {
// Generate a random number between HOP_MIN and HOP_MAX
float randomFrequency = HOP_MIN + (Entropy.random() % (HOP_MAX - HOP_MIN + 1));
// Log frequency
Serial.print("Hopping to: ");
Serial.println(randomFrequency);
return randomFrequency;
}
void setRadioFrequency(float frequency) {
// Placeholder function for setting the radio frequency
// You would replace this with actual code to control your specific radio
}