queueList peeking


I’m trying to make a traffic intersection, with 3 traffic lights and sound. Those 3 trafficlights also have a button, so the system knows that someone is waiting.
Because there can be more than traffic light waiting to be green, I want to make and queue.

The library queueList.h does this for me. I can push an number (1, 2 or 3) in, and when the time is right it can deliver the number of traffic light that can be green.

The problem is: When a person pushes multiple times the button, the number of trafficlight will be pushed in the queue multiple times. I want to restrict this to 1. The queueList library has an option to peek, but only to the first item in line.

How can I peek all the items in the queue, so I can make an function that checks if the item that wants to be pushed in isn’t a duplicate??

So far I only have this code:

#include <QueueList.h>

QueueList <int> queue1;

void setup() {
  queue1.setPrinter (Serial);


void loop() {


Thanks in advance, you will be close to saving many lives :stuck_out_tongue:

How can I peek all the items in the queue, so I can make an function that checks if the item that wants to be pushed in isn't a duplicate??

Create your own class, with the functions you need.

If I could create my own class, I would have done it..

When the button becomes pressed and you put the event in the queue set a flag to indicate that it has been queued. When the event is in the queue has been actioned clear the flag. Do not allow the action to be put in the queue whilst the flag is set.

What Paul said. It would be pretty trivial to create a FILO array, where each time you push an item, it relocates the contents down by 1. It would only need to be the size of the maximum number of buttons too, if you impose a unique restriction.

Alternatively, devise some method to remember what you pushed into your queuelist, then don't push it again until its been popped.

I think this is one of those cases where a library is more trouble than it is worth (unfortunately, a common situation).

A circular array is easy to implement. Just create an array and use two variables to point to the head and tail of the list. When the head and tail are the same the list is empty.

You add a value to the array element pointed to by the tail. Then you increment the value of tail. If the value is greater than the length of the array, make the value 0 so it "circles".

You take a value from the element pointed to be the head. Then decrement the value of head etc.

Draw it out as a series of boxes on a piece of paper and put some data in the boxes and you will quickly see how it works.