Hey there!
I'm trying to modify an item (struct) inside a QueueArray (using Arduino Playground - QueueArray Library) using the following code:
timedPin *currentPin = &timedPins.peek();
*currentPin->pin = 28;
Serial.println(timedPins.peek().pin);
However, upon compiling, I get "error: invalid type argument of 'unary *'" on the second line. Now I'm quite new to pointers and C in general, but I assume my thought should've been about right:
- Grab a pointer to the queue item returned from peek()
- Modify member pin of said pointer to modify member pin of the queue item itself
- timedPins.peek().pin should show the difference
Also, when I'm doing it without using pointers, it doesn't change the value either.
Would be nice if someone could help me out!
Greets,
Philipp
You can't assign the value 28 to a pointer to a function.
"peek" returns the value of the item, not the item itself, so the thing you're taking the address of is the function "peek", not the item it returns the value of.
But how would I go about retrieving the value peek() returns AND being able to modify it?
pop the old value and push the new one.
Which doesn't work in my case because the pushed new value will land atop the queue when I need it to be at the beginning 
The header file you linked is for a stack (Last In First Out), not a queue (First in First Out).
Why don't you tell us what you're trying to do, not how you think you should do it?
Oh, I'm sorry.. I meant to link to this file: Arduino Playground - QueueArray Library
Basically I'm trying to queue up items of a structure:
typedef struct {
int pin;
int time;
int counter;
} timedPin;
I'm trying to increment counter in every loop and check against time. If counter == time then the item is popped. (The pin setting was just testing).
Greets,
Philipp
Why don't you tell us what you're trying to do, not how you think you should do it?
A stack is only ever interested on what is on top of the stack, and a queue is only ever interested in what is at the head of the queue.
AWOL:
Why don't you tell us what you're trying to do, not how you think you should do it?
Ok, here's the exact description:
I'm trying to stack up a queue of pins I want to pull HIGH one after another for a fixed period of time. So when the first pin's time's up, I want the next pin in the queue to go to HIGH and so forth.
AWOL:
A stack is only ever interested on what is on top of the stack, and a queue is only ever interested in what is at the head of the queue.
Well, all I'm interested in is the item at the head of the queue, but I want to modify it as well..
Greets,
Philipp