Populating then Referencing a Dynamic List of Variables (Array?)

Hey Guys -

Working on a unique project with a tea5767 and am trying to have it build a list of "strong" frequencies during setup, then have it tune to each for 5 seconds (looping the list indefinitely) when done.

The best method I can think of would be to perform a scan using tea5767's library and for frequencies where printSignalStrength() is greater than x, append the frequency to an array. In the loop, I could have it simply tune to each array variable for 5 seconds each.

My questions are...

  1. Would an array be the best method (or even work) for setting up something like this?
  2. If so, the number of variables in the array may be dynamic each startup. Without knowing this, how could I ensure each frequency is accessed when tuning to each in the loop?

I couldn't find existing code which did something similar to this, but if you do or have other suggestions; please share:)

Thanks!

Sounds like an arrray would do perfectly.

It has to be big enough to hold as many frequencies as you are interested in ever having in the list. And an array of an appropriate type (integer, long, float whatever) to represent the frequency.

Keep a variable that just counts how many you found during the scan, and only refer to or use later that number of entries.

HTH

a7

do you know (or do you have an idea) of how many strong frequencies you would want to memorise?

the simplest way is indeed a static array of the max size, and you keep a variable telling you where is the next open entry.

Once the setup is done, that variable is basically the max index and you can use it to loop reading in the array

EDIT: @alto777 was faster, same idea :slight_smile:

Haha, @J-M-L was slower with a better description of the approach!

Watch where you increment that “next slot”/counter variable or it will be one greater than the max index you can use later.

a7

How many frequencies are you expecting ? Since memory is anyway not infinite, you may as well declare an array with a finite number of entries. If you do decide to declare variables dynamically you run the risk of running out, causing unexpected behavior.
Another thing would be that if you have more frequencies that are strong enough, you could just delete the weakest from the list.

Awesome - Thanks, guys. Will try giving it shot this weekend if I have time. Guess I first need to figure out how to use arrays in those regards.

Appreciate it!

This isn't another one of those "Ghost radios" is it?

-jim lee

jimLee:
This isn't another one of those "Ghost radios" is it?

No, but can turn into one if you know the stations they like :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.