In this lesson, I'm going to show you how to use the time functionality to get the current time in
your out in a program and later on in the following lessons, you would see that with these we are able
to solve the delay problem.
So how to get the time, whether you have a function called Moelis so minutes, it should arrange,
of course, because this is an added function and this will give you the current time.
But what current time and talking about is it like for example, today is Thursday, it is 10:00 a.m..
Now, this is not the current time you would get you would get the time since the original program started.
So when you start the program, the time will be zero after two seconds where you will get to a second
and he amylase will give you the time in minutes to talk to two segments.
You will get 2000.
So now what we can do with this function?
Well, we can actually store it if we want to use it later and to store it, we need to use unsigned
long.
So let's say time now.
Milice.
And forget the semicolon.
So a few things to explain here.
First, you can see I use unsigned, OK, but what is unsigned?
So unsigned goes with another data type, for example, long, unsigned, int and state, long, etc.
Unsigned simply means that all the numbers would be positive.
So they arranged for a data type which starts at zero.
If you remember all along we have minus.
So we can go from minus two billion, approximately two plus two billion.
OK, that is the range of the law.
You can go in a negative number.
You can go in a positive number, up to two million.
Now, if you add unsigned.
The along what it will do, it will shift in the numbers to all the negative number, you can't get
them, but instead it will be added to the maximum number.
So you will start at zero.
Up to plus will be approximately.
OK, so here why do we use unsign long?
Because, well, time in Alvino starts at zero and then it continues to increment.
So we don't need to start any negative number, OK.
The time will never be negative when you get with Mitty's.
So we use unsigned long and now.
So to name the variable I could just have used.
Let's say the time is Milice, but here you can see the time when I right.
Time returns around.
OK, so that is another best practice I want to show you here is that when you create a name for a viable
or meaningful function as well, if you see that the name turns around are for example, green or blue,
well, that probably means that this is a reserved keyword.
But if you try to declare valuable or function with a name that may cause a conflict where you may have
some problem in the future, who here?
Maybe you don't know if time is a function or not, but since it orangish, it may be a good thing to
change the name.
So it's for your full time.
All right.
So avoid using resiled keywords and functions.
And to do that you can get help with the column.
All right.
End of the power outages here.
I'm going to remove that so we have the time, OK?
And now what I can do with the time I can print at the time, if I want to say that, let's say I begin.
Both right and no, I get time and I can do that.
Alan, we have time now so I can directly print, I could print directly inside the print are here because
I have a viable I'm going to use the available and let's upload new code to the original.
So make sure it's connected.
Muris.
OK, I'm going to open the sale Moniteau, and we get here, we get to Xeros because we still had some
kind of buffer.
Now, if I press the reset button on the adeno, I will get just one zero.
The other two, you hear the time we return zero because, well, we are just at the beginning of the
program is the first things that gets executed.
Now, let's say I use a delay here of one single one telling me since I can upload the code.
And you can see we have so we don't have exactly 1000.
We have nine hundred and ninety nine because you don't necessarily get one hundred percent precision,
but this is really quite close.
OK, so you can see that after one segment in the program, when we get Milice, we get one signal.
OK, so we can know that the program has started one second ago and what we can do let's see here in
the loop that even that sprint Mitty's and Sprint every the lead with.
Every one Segan.
OK.
So I'm going first to predict what's in the set up and then every single in the function and you can
see here, but we have one, two, seven, three second forcing cetera.
OK, but keeps incrementing.
All right, so nothing really difficult here when you start the program.
The time starts at zero and then it keeps incrementing and you can get to ten minutes to it with unsigned,
long, mineable.
And another thing is you can also get the time using micro.
Here what is micro?
It is the same thing as Milice, but giving the time in microseconds.
So if you need to have more precision than one millisecond, then you can use microcircuit.
So basically with time you have four different functions.
You have the delay with millisecond delay, microseconds with microseconds.
And then tomorrow the time you have minutes when milliseconds and micros, which gives you the time
in microseconds if I run the program now.
And you can see here we have so once again to see three things, etc., it keeps incrementing just the
numbers multiplied by one thousand.