Dynamic Array?

How would a dynamic array work?

I'll have a list of parameters 'available', and from this I want to be able to allow the selection of .. 8 .. parameters, the parameters can change at run time if the user chooses using the LCD and some push buttons.

So I can find the button push (catch interrupt), I can decide what options they are to look at by having a list and simply displaying some strings, I can display the options ( with a X next to them), what I need is some way to determine which are active - a dynamic array!. If they deselect an option, the option needs to go from the array, and the array needs to reposition contents to suit.
If they add an option to the array, it needs to get appended to the end!

Any thoughts on how that's best done?

byte[8] active_Options;
#define OPTION_1 0x01
#define OPTION_2 0x02
... and so forth to 20.

active_Options = { OPTION_1, OPTION_2, OPTION_3, OPTION_7 };

Hi,
Us bit flags instead, a single 8 bit byte gives you 8 on/off bit flags, a single 16 bit int gives you sixteen and a long gives you 32. Pick whichever fits your purpose, it works like this

#define SOUND_FLAG 1
#define COLOUR_FLAG 2
#define VIDEO_FLAG 4
#define STEREO_FLAG 8
// etc etc 16,32,64,128, notice that we double the value each time, this ensure each flag uses the next bit in our byte, int or long

byte bFlags;

to set a flag use

bFlags |= VIDEO_FLAG;

to clear a flag use

bFlags &= (!VIDEO_FLAG);

to test a flag use

if(bFlags & VIDEO_FLAG) // the video flag is set

This approach is 8 times more efficient that your current approach without even taking account of the extra code that would be used to manage your dynamic array.

Search for C bit wise operators for more information on this approach

Duane B

rcarduino.blogspot.com

Fantastic idea Duane..