Need Help Using QueueArray

I’ve just discovered QueueArray and have been trying to use it. I find the docs a bit opaque… :fearful:

I want a FIFO of request byte codes. When program sends a request to the Mega, I forward it to an attached device, and put a byte-code in the queue. Then later I’ll take the next item from the queue to determine how to use the incoming response.

Queue Instantiation: QueueArray REQ_QUE;

Adding a Request Code to the queue: REQ_QUE.enqueue(LOGREQ);

From here I can’t figure out how to remove the next item to a local var for eval. When I tried this syntax:

x = REQ_QUE.dequeue(); where x is a local byte var

Simply having this line of code in the Mega causes pin 13 to toggle at a 2-hz rate!! So I obviously am missing something big

So - Assuming I’m enque’ing correctly, how to I get to the next item out of the queue for eval?

I find the docs a bit opaque

You have the considerable advantage that you have found them.
What is QueueArray and where are the docs?


Sounds like a standard ring buffer concept to me but, like Robin says, you have the advantage of us here.

Usually it just involves an array and two separate indexes. One of the indexes is called "the Head" and the other "the tail". When both the head and tail are pointing to the same point in the queue, the queue is empty.

To put a new item in the array you add it at the point being indexed by the head, then increment the head (resetting it to zero if it goes beyond the array length).

To read an item from the queue you read the item being pointed to by the tail and increment the tail (resetting it to zero if it goes beyond the array length).

something like this would be a simple example

#define queueLength 20
int queue[queueLength];
int head = 0;
int tail = 0;

bool queueAvailable()
return (head != tail);

int queueRead()

int value = queue[tail++];
if (tail == queueLength)
  tail = 0;

return value;

void queueWrite(int newValue)
queue[head++] = newValue;
if ( head == queueLength )
  head = 0;
1 Like