Closed wrybread closed 1 year ago
thanks for sharing to user it may help, and for your interest in, using Queue library!
You may create your own example as a new sketch in examples folder and make a pull request.
Regards, SMFSW
@wrybread I really liked your example as it was more straight forward and closer to the idea I would want to implement in a project of mine. However, I ended up unable to run it properly on my Arduino Uno. I was so confused because if I modified it to take integers instead then it worked. It eventually occurred to me I might be running out of RAM and well sure enough by cutting down a few things I was able to get it working with the char arrays! So if anyone else was having issues getting it to work then here's what I ended up with to get it to work:
#include <cppQueue.h>
typedef struct strRec {
/* Reduced both char array sizes significantly as they were extremely
large and causing the program to not work correctly */
char url[50];
char misc1[50];
} Record;
cppQueue queue1(sizeof(Record), 10, LIFO, false);
void setup() {
Serial.begin(9600);
Record test = { "http://google.com", "some stuff" };
queue1.push(&test);
}
void loop() {
// iterate through the queue
while (!queue1.isEmpty()) {
Record queueRecord;
queue1.pop(&queueRecord);
/* Surrounded the String in F() to move it from RAM
to the flash memory (which there is more of) */
Serial.println(F("There's something in the queue!"));
Serial.println();
Serial.print(queueRecord.url);
Serial.print(" ");
Serial.print(queueRecord.misc1);
/* NOTE: Using the String class increases the flash memory
and RAM usage but I didn't need to remove this */
Serial.println();
String url = queueRecord.url;
Serial.print("URL = ");
Serial.println(url);
Serial.println();
}
delay(1000);
}
I had some trouble using the SimpleQueue.ino example script, here's SimplerQueue.ino on the off chance it's useful to anyone: