WEBVTT

00:00.210 --> 00:05.380
In this lesson, I'm going to show you how to use the time functionality to get the current time in

00:05.380 --> 00:10.860
your out in a program and later on in the following lessons, you would see that with these we are able

00:10.860 --> 00:12.350
to solve the delay problem.

00:12.810 --> 00:19.590
So how to get the time, whether you have a function called Moelis so minutes, it should arrange,

00:19.590 --> 00:23.850
of course, because this is an added function and this will give you the current time.

00:23.880 --> 00:31.070
But what current time and talking about is it like for example, today is Thursday, it is 10:00 a.m..

00:31.710 --> 00:37.530
Now, this is not the current time you would get you would get the time since the original program started.

00:38.040 --> 00:45.320
So when you start the program, the time will be zero after two seconds where you will get to a second

00:45.750 --> 00:50.430
and he amylase will give you the time in minutes to talk to two segments.

00:50.430 --> 00:51.690
You will get 2000.

00:52.170 --> 00:54.810
So now what we can do with this function?

00:54.810 --> 01:02.000
Well, we can actually store it if we want to use it later and to store it, we need to use unsigned

01:02.190 --> 01:02.800
long.

01:03.060 --> 01:05.280
So let's say time now.

01:06.470 --> 01:07.010
Milice.

01:08.040 --> 01:09.400
And forget the semicolon.

01:09.930 --> 01:11.480
So a few things to explain here.

01:11.880 --> 01:16.530
First, you can see I use unsigned, OK, but what is unsigned?

01:17.130 --> 01:23.040
So unsigned goes with another data type, for example, long, unsigned, int and state, long, etc.

01:23.460 --> 01:27.440
Unsigned simply means that all the numbers would be positive.

01:27.570 --> 01:31.290
So they arranged for a data type which starts at zero.

01:32.370 --> 01:36.810
If you remember all along we have minus.

01:36.870 --> 01:43.640
So we can go from minus two billion, approximately two plus two billion.

01:43.780 --> 01:45.880
OK, that is the range of the law.

01:46.380 --> 01:47.930
You can go in a negative number.

01:47.940 --> 01:50.850
You can go in a positive number, up to two million.

01:51.420 --> 01:53.010
Now, if you add unsigned.

01:55.220 --> 02:02.390
The along what it will do, it will shift in the numbers to all the negative number, you can't get

02:02.390 --> 02:05.750
them, but instead it will be added to the maximum number.

02:06.080 --> 02:07.550
So you will start at zero.

02:07.970 --> 02:11.660
Up to plus will be approximately.

02:11.960 --> 02:14.150
OK, so here why do we use unsign long?

02:14.150 --> 02:19.880
Because, well, time in Alvino starts at zero and then it continues to increment.

02:19.910 --> 02:22.120
So we don't need to start any negative number, OK.

02:22.160 --> 02:25.810
The time will never be negative when you get with Mitty's.

02:26.510 --> 02:29.690
So we use unsigned long and now.

02:29.690 --> 02:33.230
So to name the variable I could just have used.

02:33.560 --> 02:39.530
Let's say the time is Milice, but here you can see the time when I right.

02:39.530 --> 02:41.110
Time returns around.

02:41.210 --> 02:49.040
OK, so that is another best practice I want to show you here is that when you create a name for a viable

02:49.130 --> 02:56.500
or meaningful function as well, if you see that the name turns around are for example, green or blue,

02:56.900 --> 03:01.740
well, that probably means that this is a reserved keyword.

03:01.970 --> 03:08.810
But if you try to declare valuable or function with a name that may cause a conflict where you may have

03:08.810 --> 03:11.090
some problem in the future, who here?

03:11.090 --> 03:18.200
Maybe you don't know if time is a function or not, but since it orangish, it may be a good thing to

03:18.200 --> 03:18.880
change the name.

03:19.520 --> 03:21.170
So it's for your full time.

03:22.160 --> 03:22.490
All right.

03:22.520 --> 03:26.780
So avoid using resiled keywords and functions.

03:27.200 --> 03:29.850
And to do that you can get help with the column.

03:30.260 --> 03:30.710
All right.

03:30.710 --> 03:32.380
End of the power outages here.

03:32.690 --> 03:36.580
I'm going to remove that so we have the time, OK?

03:37.340 --> 03:43.190
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.

03:45.790 --> 03:50.100
Both right and no, I get time and I can do that.

03:51.070 --> 04:00.820
Alan, we have time now so I can directly print, I could print directly inside the print are here because

04:00.820 --> 04:05.620
I have a viable I'm going to use the available and let's upload new code to the original.

04:05.710 --> 04:07.450
So make sure it's connected.

04:10.240 --> 04:10.960
Muris.

04:12.060 --> 04:20.400
OK, I'm going to open the sale Moniteau, and we get here, we get to Xeros because we still had some

04:20.610 --> 04:21.610
kind of buffer.

04:21.930 --> 04:27.280
Now, if I press the reset button on the adeno, I will get just one zero.

04:28.380 --> 04:34.320
The other two, you hear the time we return zero because, well, we are just at the beginning of the

04:34.320 --> 04:37.480
program is the first things that gets executed.

04:37.860 --> 04:46.650
Now, let's say I use a delay here of one single one telling me since I can upload the code.

04:48.840 --> 04:51.790
And you can see we have so we don't have exactly 1000.

04:51.810 --> 04:56.280
We have nine hundred and ninety nine because you don't necessarily get one hundred percent precision,

04:56.280 --> 04:58.360
but this is really quite close.

04:58.380 --> 05:06.180
OK, so you can see that after one segment in the program, when we get Milice, we get one signal.

05:06.180 --> 05:13.290
OK, so we can know that the program has started one second ago and what we can do let's see here in

05:13.290 --> 05:22.350
the loop that even that sprint Mitty's and Sprint every the lead with.

05:23.470 --> 05:24.980
Every one Segan.

05:25.050 --> 05:25.410
OK.

05:26.600 --> 05:33.230
So I'm going first to predict what's in the set up and then every single in the function and you can

05:33.230 --> 05:40.330
see here, but we have one, two, seven, three second forcing cetera.

05:40.400 --> 05:42.550
OK, but keeps incrementing.

05:44.000 --> 05:47.130
All right, so nothing really difficult here when you start the program.

05:47.150 --> 05:55.970
The time starts at zero and then it keeps incrementing and you can get to ten minutes to it with unsigned,

05:55.970 --> 05:57.180
long, mineable.

05:57.620 --> 06:01.850
And another thing is you can also get the time using micro.

06:03.110 --> 06:04.210
Here what is micro?

06:04.250 --> 06:09.530
It is the same thing as Milice, but giving the time in microseconds.

06:09.860 --> 06:15.470
So if you need to have more precision than one millisecond, then you can use microcircuit.

06:15.800 --> 06:18.790
So basically with time you have four different functions.

06:18.800 --> 06:23.980
You have the delay with millisecond delay, microseconds with microseconds.

06:23.990 --> 06:29.420
And then tomorrow the time you have minutes when milliseconds and micros, which gives you the time

06:29.420 --> 06:33.170
in microseconds if I run the program now.

06:36.640 --> 06:44.980
And you can see here we have so once again to see three things, etc., it keeps incrementing just the

06:44.980 --> 06:47.500
numbers multiplied by one thousand.
