Now it's time to implement our cue, so in this example, we're going to create a task that is going
to send values to the queue and we're going to bring the status of the queue and we are going to see
when it's full, when it's empty.
We won't be receiving anything right now in this portion of the video, we will only be transmitting
values to the queue.
The first thing we want to do is we're going to add the library responsible for that.
And to do that, we're going to simply create and include.
And we're going to include Q.
So they know let us first create the CU handle.
We know this line already, I did not delete it because we've already got it multiple times in order
to create delays and for our jobs, we need to do this macro so that our job is easy whenever we want
to create a delay.
Now we need to create the handle as usual, so we have a queue and the understandable underscore t.
And we're going to call this excuse.
We have created the handle by now.
Let us go to the set up.
And in the set up, we're going to create our serial.
Nothing special.
And we are going to create to test the first one is going to be, let's say test create.
Now we're going to create a task, so we're going to stay as task.
Create.
And we're going to call it the X Desk, meaning sending Dask.
I'm going to call that center.
The buffer is, let's say, only 20.
No.
Priority one and.
No, let us go to the loop and now the loop will stay empty.
And now it's time to write our test, so it's going to be void the next task.
Lloyd Poynter.
No.
We have created a task, but we did not create the cure yet, so we need to create the cure as well.
I'm going to say excuse.
As equal to excuse.
Create.
Now, what is the size of MICU, let's say we can fit five elements, it could be of any type, it could
be five array's five structures, five integers.
We can do whatever we want, though.
Let's say it's five.
And what is the time it's going to be size of.
India, now, what is that?
I am telling it that every element of this queue is going to fit an integer, but do I know what is
the size of my integer?
Well, if I call this function here, it's going to automatically tell me what is the size of my integer.
I mean, here I could be the size of character.
So it will be five sizes of characters, let's say is one byte.
So it will be five one bytes.
Now let's say size of an integer.
In this case, let's say the integer is 16 bits or two bite.
So it will be five two byte in sequence next to each other.
OK, so the size of is going to tell me what is the size of my data type for every element of this.
OK, so in this case it is five times what is the size of integer.
It's 16 bits so it is five times sixteen.
It is eight bits or we can say five times to bytes it is ten points.
So this skew can fit ten boats and every element has to bite size.
All right.
Next, I'm going to create a minimalist example so that we can understand the concept.
Nothing complex.
I'm going to be sending a continuous value all the time.
The same value to the queue.
It's going to be integer.
Data, I'm going to call the data one, two, three, so the volume is one hundred twenty three.
OK, I'm going to be filling my queue with these values repetitively.
Now I'm going to create a while loop.
In order to go infinitely.
And the first thing I want to do is I'm going to be sending values right?
I'm going to say excuse.
Then this is the function in order to send the cue from a desk.
First I need to specify to which queue I want to send.
Well, I have only one queue in my case, so it is to execute.
OK, next is what is my data?
Remember I told you that we are copying the data and we are not sending it as it is.
So in order to send a reference to this data or copy it, we are going to use the end sign and we are
going to say data.
This will make sure that a copy of this data will be sent to the queue.
OK, so this operation here is for copying or taking a reference to that data.
Finally, we need to see how long should we wait if we cannot send data?
Well, I'm going to wait indefinitely.
So we're going to use, as usual, the max delay.
So if the queue is full, how long do I need to wait until I send my next data?
Well, I want to wait until it's ready until the queue is emptied by one element so that I could fit
my new element to.
OK, so let us bring some stuff to the serial monitor, so serial friend Len.
Oh, let's not Joselin now, I'm going to say.
Data sent.
Like, what is the data I'm sending right now and now I'm going to print cereal, that friend Len.
Data, I'm going to print the data I am sending and I'm going to go for a delay, let's say delay for
one second.
OK, now this is a minimized example.
Now my Audrina is connected, I'm going to upload.
Let's see how many data will be printed.
One, two, three, four, five, OK, so we have printed five values, and that makes sense because
our Q can fit only five values and this is exactly what's happening now.
If I click this and I reset my Adreno by the reset button.
Again, I'm sending one, two, three, four, five.
So right now, my queue is full of five values.
Each value is one hundred twenty three.
OK, that's a great.