WEBVTT

00:00.180 --> 00:03.180
This is that number nine of the final project.

00:03.470 --> 00:10.020
So instead we are going to allow the user to change the distance you need to between centimeters and

00:10.020 --> 00:16.430
inches so the user will be able to toggle between the two using the remote controller.

00:16.890 --> 00:23.550
And then what we also want to do is to make sure that we save the default unit for the next time we

00:23.550 --> 00:24.550
restart the program.

00:24.870 --> 00:29.190
So the default unit is centimeters and will restart its centimeters.

00:29.490 --> 00:34.730
If the default unit is inches and then we restart, then the default unit will be inches.

00:34.740 --> 00:36.570
And for that we are going to use EPROM.

00:36.600 --> 00:45.120
So for this step three small thing we need to do first go the distance units using the remote controller,

00:45.420 --> 00:50.340
then print of course, to create a unit on the LCD and save it to April.

00:51.060 --> 00:53.480
So let's start by defining here.

00:53.490 --> 00:55.800
I'm going to add some define.

00:57.800 --> 01:03.400
Define distance, you need centimeter.

01:03.510 --> 01:04.830
I'm going to use some define.

01:04.850 --> 01:14.030
OK, let's put here the value is really not important defined distance unit and let's put in four inches.

01:15.080 --> 01:20.720
So by doing this, you can see that if you want to add, for example, in the future another unit that

01:20.870 --> 01:21.860
you want to print in.

01:21.860 --> 01:22.820
Mm.

01:22.820 --> 01:28.490
In meters, in feet, in whatever unit you can just add multiple defines you.

01:28.730 --> 01:37.520
OK, and I'm going to create a global variable, let's put it there after is looked into this dense

01:38.030 --> 01:42.720
unit and initialize it to distance units centimeters.

01:42.740 --> 01:48.050
So that would be the default unit when you first start the program for the first time.

01:48.380 --> 01:54.520
And actually one note here is that we aren't going to change the computations to inches in the program.

01:54.890 --> 01:56.470
We keep centimeters.

01:56.960 --> 01:59.240
We will use centimeters for all computations.

01:59.240 --> 02:05.540
And then only then when we want to print on the LCD, we are going to toggle between the two units.

02:05.930 --> 02:08.760
So I'm going to create now a new function.

02:08.780 --> 02:10.530
So let's go down.

02:10.550 --> 02:13.630
So we have a handle I command.

02:13.640 --> 02:15.060
I'm going to create the function here.

02:15.440 --> 02:17.930
So the other here, not that important.

02:20.890 --> 02:23.710
Distance unit, OK?

02:25.270 --> 02:26.530
And I'm going to if.

02:28.810 --> 02:32.560
Distance you need is equal to.

02:32.830 --> 02:37.480
So let's go back here to the distance, you need centimeters.

02:40.680 --> 02:47.640
Then we say that the distance you need becomes inches and then else.

02:50.690 --> 02:52.240
Distance you need.

02:54.130 --> 02:59.440
Becomes it, so we just toggling between the two and note that here.

02:59.470 --> 03:06.130
So with this, you may recognize the opportunity to use the one line, if which you may do so if you

03:06.130 --> 03:07.320
only have two states.

03:08.020 --> 03:14.490
And the thing is, I'm not using that here because maybe we can in the future add other units.

03:14.770 --> 03:21.290
And also, if you add other units in the future, that may be also a good idea to change that if as

03:21.380 --> 03:23.910
if as into a switch.

03:23.950 --> 03:30.290
OK, but I'm going to give that if elsea because it's also convenient, basically switch and if you

03:30.310 --> 03:31.950
are doing the exact same thing.

03:32.320 --> 03:36.970
So I'm just toggling between the centimeter and inches when I call this.

03:37.360 --> 03:42.000
So what I can do now is I have chosen the ECU button.

03:42.010 --> 03:42.990
So why BQ?

03:43.030 --> 03:44.020
Well, why not?

03:44.320 --> 03:48.700
So when I press on the ECU button, I toggle the distance unit.

03:48.740 --> 03:51.910
So if it was centimeters, it's going to be inches.

03:52.240 --> 03:57.550
If it was inches is going to be centimeters and the first default value is centimeters.

03:58.130 --> 04:04.480
Now that we have toggled distance unit, we need to make sure that we print the correct unit on the

04:04.480 --> 04:05.710
LCD screen.

04:05.920 --> 04:07.720
So when we print here.

04:09.260 --> 04:13.790
This OK, and then dist. centimeters, I'm going to add it if you.

04:15.570 --> 04:22.830
Distance unit is equal to so actually distance units centimeters.

04:24.430 --> 04:26.530
Let's use inches here instead.

04:27.580 --> 04:35.530
And say footprints in inches and the default so else will be the default behavior and a default will

04:35.530 --> 04:36.460
be centimeters.

04:37.700 --> 04:41.160
Just like centimeters in the default unit.

04:41.180 --> 04:43.310
So that will make things simpler.

04:43.820 --> 04:46.570
So if it's in inches, we're going to break in inches.

04:46.590 --> 04:55.070
And so if it's in centimeters now, because we only have two units, we print the distance centimeters,

04:55.070 --> 04:58.360
everything like we did before, quite normal.

04:58.490 --> 05:06.740
Now, what we need to do here, the print we would need to convert the distance that we have here.

05:08.300 --> 05:15.590
From centimeters to inches distance that we would need to multiply by something and what are we to do

05:15.590 --> 05:17.270
here to make it easier?

05:17.300 --> 05:27.700
I'm going to add another here, a define and call this centimeter two inches.

05:27.710 --> 05:30.010
So just like this, for example.

05:30.350 --> 05:39.150
And then I'm going to put the conversion factor, which is zero point three nine three seven one.

05:39.560 --> 05:40.850
Where did I get that?

05:40.850 --> 05:46.430
Will simply nutile centimeters, two inches in Google and you get that result.

05:46.850 --> 05:53.390
So I just stop right here so I can just instead of hard cutting this number.

05:54.610 --> 05:59.230
I can just do in my print the.

06:00.280 --> 06:07.580
Function again, the distance multiplied by centimeters, two inches, and this is actually a good practice,

06:07.610 --> 06:14.380
OK, when you need to convert between units, for example, you could have degrees and Rajan's for an

06:14.380 --> 06:14.860
angle.

06:15.160 --> 06:23.800
You could have sensors are finite for a temperature or here inches or centimeters or millimeters or

06:23.800 --> 06:26.770
whatever, then just creates and defines.

06:26.920 --> 06:34.420
OK, first you need to Sigrun you need and then you just need to multiply by these defined which makes

06:34.420 --> 06:35.540
more sense in your program.

06:35.560 --> 06:36.820
OK, it's much more reading.

06:38.060 --> 06:39.620
And then we do ethnic prince.

06:41.270 --> 06:49.110
With space and endless put in and a few other species, right, so now we can toggle the unit, we can

06:49.110 --> 06:53.460
print a different result on the acidy depending on the unit.

06:53.880 --> 07:01.410
And the thing is not if we restart the ALINO program and if it was inches, then when we restart, it's

07:01.410 --> 07:07.020
going to still be the default value, which is right here.

07:08.170 --> 07:10.790
Distance units in distance units centimeters.

07:11.590 --> 07:14.810
So what I'm going to do now is to save.

07:14.830 --> 07:23.170
So when we told you when we took out the distance units, I'm going to save that new distance unit into

07:23.170 --> 07:23.750
April.

07:24.130 --> 07:29.310
And when we start the program in the set up, I'm going to read that unit.

07:29.650 --> 07:35.060
So I'm going to insulate it from here, include people.

07:36.460 --> 07:42.310
All that locate and after all those designs, I'm going to add here.

07:43.690 --> 07:47.200
Define EPROM address.

07:48.770 --> 07:56.380
Distance unit, I'm going to create define for, let's say, 50, so we are going to use the address

07:56.450 --> 08:00.320
50 of the EPROM to store the distance unit.

08:00.890 --> 08:04.310
OK, so what we do in the Tuggle.

08:06.180 --> 08:08.280
Distance unit, I'm going to do.

08:09.420 --> 08:16.920
Is that right, we've addressed that we have so the address is here.

08:19.820 --> 08:23.360
It's right here and distance.

08:25.430 --> 08:33.530
OK, note that because we use EPROM, that's right, what you might want to do is to use Assael, not

08:33.560 --> 08:39.890
print here, run the program first and see when you get to that point, OK?

08:40.400 --> 08:45.500
If you only get to the point when you press on the button on the remote control, that's fine.

08:45.800 --> 08:51.190
But if you have a problem and this is called very, very, very frequently and you want to check before

08:51.200 --> 08:54.080
you're right on the problem, so I'm not going to do it.

08:54.080 --> 08:58.710
But that's a good practice you can do before you're right with EPROM, right.

08:59.030 --> 09:06.400
So I have saved my value when I toggle the distance unit, not in the setup, what I can do simply.

09:06.830 --> 09:08.800
So let's do that here, for example.

09:09.230 --> 09:11.030
It's not really important the way you do it.

09:12.230 --> 09:15.080
I can do distance unit.

09:16.090 --> 09:21.460
Is equal to promote trade with the onerous.

09:22.640 --> 09:29.480
And just I'm going to make sure that even a distance unit is equal to 255, which can happen.

09:31.340 --> 09:34.100
And the distance unit becomes.

09:35.190 --> 09:35.880
Zero.

09:35.910 --> 09:42.340
I'll just make sure that it is the distance in each 30 meters.

09:43.920 --> 09:44.970
So when you read from the.

09:49.350 --> 09:56.600
You also want to validate the data in case you have a written invalidated before he undoing the simple

09:56.600 --> 09:59.580
logic and checking for the two hundred fifty five value.

09:59.980 --> 10:07.770
But what you may also do is check for each dist. unit that you have that corresponds to one.

10:07.920 --> 10:12.780
And if it doesn't correspond to any of the distance unit, you can use the default one.

10:13.170 --> 10:13.480
OK.

10:13.500 --> 10:15.720
So no, I think the code is complete.

10:15.730 --> 10:18.420
So let's first verify it.

10:19.590 --> 10:21.600
Final project, Stepanov, the nine.

10:24.370 --> 10:27.070
OK, and as a quick recap, so.

10:29.100 --> 10:35.880
We create toggle distance unit function that we call when we pressed the ECU button on the remote control.

10:36.990 --> 10:43.710
In that we toggle between the two different distance units, centimeter inches that we have used.

10:44.070 --> 10:51.750
So we have created a defined for each and the global viable to keep the distance unit once we toggle

10:52.110 --> 10:52.810
the unit.

10:52.860 --> 10:55.520
We also write it to the people.

10:55.920 --> 11:01.350
Then when we print on the LCD, when we call that function within a distance, we're going to check

11:01.350 --> 11:02.560
for the distance unit.

11:02.580 --> 11:05.580
If this is inches, we print in inches.

11:05.790 --> 11:08.530
If it's centimeters, we print in centimeters.

11:08.910 --> 11:11.280
Now, let's say you restart the program.

11:12.090 --> 11:18.900
Now, in the setup, you're going to read from the address for the distance unit and sits the distance

11:18.900 --> 11:24.720
unit with the previous setting that you have set when you press the button in the previous frame.

11:24.930 --> 11:25.320
All right.

11:25.320 --> 11:28.290
So now let's upload to the original.

11:31.720 --> 11:37.330
So now you can see the distance in centimeters, of course, that's the normal behavior we always had

11:37.330 --> 11:37.940
before.

11:38.230 --> 11:44.470
So 136 centimeters now going to press on the issue button here.

11:47.560 --> 11:55.510
And so I had a low battery, so you can see that sometimes if you have low battery and the remote controller,

11:55.750 --> 12:01.760
it may be some source of problem that the command is not correctly retrieved.

12:01.990 --> 12:03.620
So now I have injuries.

12:03.760 --> 12:10.490
You can see 135 centimeters correspond to about 50, 50 something inches.

12:10.510 --> 12:14.830
OK, I can toggle between centimeters and.

12:16.090 --> 12:20.640
And cheese, and you can see that if I it so I'm going to press the reset button.

12:22.080 --> 12:25.740
Which will restart the program, initializing its inches again.

12:25.770 --> 12:32.310
OK, it's not centimeters, it's inches because we have saved the unit in the memory.

12:33.150 --> 12:35.950
All right, so everything is working now.

12:35.970 --> 12:42.930
You can choose the distance need you want to print the distance on the LCD screen for the user, which

12:42.930 --> 12:44.220
can be quite convenient.

12:44.640 --> 12:50.280
And you can see here, again, that is a really good use case for using it from memory.
