dynamic lists (report msg´s or process-queue list)

Hello everybody!
Im not sure this is even possible, so please forgive a newbie question.. :slight_smile:

Ive found some situations where i would like to have a "dynamic list" of sorts, for instance, to stack debug messages for the display output, so i have to clear each message with a button or timer before the next is displayed.

Or similarly, to have a "state-machine"-ish setup, where i could prioritize and organize what to do next in my program, depending on each functions priority rating and timing settings

Simply put, a way to add/remove items to a process-queue, so my functions can fetch the item next in line, without having to know exactly what to fetch.
I would add each item in the queue when its timer ran out, and process the queue contents depending on each items age in list, priority value or something along those lines.

I am a newbie with some minor talent, so a arrow in the right direction is more or less what im asking for here. :slight_smile:

And if this is impossible, please kill these ideas of mine, so i can bury them and move on.. :slight_smile:

To pinpoint what im after here;

I have a bunch of functions and i want the debug console (16x2 char LED) to display if a function is changing a global structure.

The functions are affected by tactile buttons, setting the system states in this global structure, later to be used by the output functions.
So the display is used as a feedback to verify that everything is happening correctly.
(to notice that the LED is ON but the LED_state is OFF and so on)

But i dont want to overwrite each message before i had the chance of reading it, meaning i would want to "stack" the messages in a queue, displaying one after the other, in the order they came in, changing to the next after a pre-set timer interval or a button press (any would suffice).

So is this possible at all?
Is it manageable by a amateur?

Thank you for your time and effort here, i greatly appreciate any help on this topic!

You want to create debug messages during the programs execution and store these in a queue. You want to be able to, asynchronously with the program flow, retrieve a message from the queue (by pressing a button or a timer), display the message on an LCD screen, then delete the message from the queue.

Of course it is possible to implement a queue for text messages etc. and implement the trigger to display the message. What is not so clear is why you want to do it this way.

For debugging purposes, I'd normally consider using Serial.print etc. to the serial console.
If there is only an LCD screen available, I'd write a message to that then suspend the program execution until I'd a chance to read the message then resume the program execution with a button press. What I don't understand is why you would want to queue the messages and display these later. The only thing I can think of is that you are processing input data at a rate which you can't control so cannot suspend processing without losing data (debugging a demodulator for example).

Maybe you could give a more concrete example which highlights the benefits of queuing the debug messages.

xarvox:
i would like to have a "dynamic list" of sorts, for instance, to stack debug messages for the display output, so i have to clear each message with a button or timer before the next is displayed.

Or similarly, to have a "state-machine"-ish setup, where i could prioritize and organize what to do next in my program, depending on each functions priority rating and timing settings

These seem to me to be two very different things.

And before considering either of them you should be very wary about any dynamic (i.e. run-time rather than compile-time) allocation of memory in the small memory of an Arduino. It is very easy to get a memory corruption.

I don't understand why debug messages would not be printed as soon as they arise? And you are unlikely to want to leave them in the program once you are satisfied that the program works properly.

The use a state-machine concept is very common. As the process moves from one state to the next another function gets called. I can't make a connection between it and a "dynamic list"

...R

You can use malloc() to allocate memory, and free() when you are done with it. Be aware that there is no exception handling on the Arduino, so you MUST check that malloc() actually worked before you try to write to the allocated memory.

You MUST free() the memory when you are done.

What you are looking for is pretty much SOP for a huge range of applications, and is even the basis on which things like MS Windows applications operate. Google "linked lists". In c++, it requires care to implement a proper, SAFE message queue, but it is entirely do-able on an Arduino.

Regards,
Ray L.