Gentlemen,
This is a small portion of code that I need to improve the efficiency with. See Below and note that every bit of code is too large to post ...
static const uint32_t USAband[13][3] = {{180000, 200000, 350000},
{350000, 400000, 533050},
{533050, 540350, 700000},
{700000, 730000, 1010000},
{1010000, 1015000, 1400000},
{1400000, 1435000, 1806800},
{1806800, 1816800, 2100000},
{2100000, 2145000, 2489000},
{2489000, 2499000, 2696500},
{2696500, 2740500, 2800000},
{2800000, 2970000, 5000000},
{5000000, 5400000, 5400000},
{0, 0, 0}};
static inline void bandplan() {
goTo(0x10);
static const char *band_print[] = {"160M",
" 80M",
" 60M",
" 40M",
" 30M",
" 20M",
" 17M",
" 15M",
" 12M",
" 11M",
" 10M",
" 6M",
" "};
bool stopped = false;
for(uint8_t band_search=0; !stopped; ++band_search) {
if(freqMEM[0] > (USAband[band_search] [0]-1) &&
freqMEM[0] < (USAband[band_search][1]+1)
|| band_search == 12) {stopped = true;
Serial3.write(band_print[band_search]);}}
}
How it works... the global variable freqMEM[0] contains a uint32_t value AKA the frequency and the function bandplan() looks to see what the frequency falls within and prints what band that it belongs in. Note, the multi dimensional array USAband[13][3] holds the boundary numbers.
Is there a way to get around the for loop and the nested if statement? I feel that this is very inefficient and could be improved upon but would like an opinion or for some one to show be a better way to do this.
FYI, I am using a Teensy 3.1 with the Arduino IDE.
Thanks in advance
Bryan