WEBVTT

00:00.270 --> 00:07.740
This is the solution of the previous activity where you have to make an entity fade in, fade out from

00:07.920 --> 00:15.710
directly from the potential meter, and on top of that, you add a cap value that you set from the sale.

00:15.900 --> 00:19.880
And when you set the cover, you from the sale, you also save to it.

00:20.310 --> 00:24.520
So the next time you start the program, you keep the same default setting.

00:25.290 --> 00:27.130
So we have a few different things to do.

00:27.300 --> 00:34.290
Let's go step by step and let's choose the first thing to do so we can directly validate what we are

00:34.290 --> 00:35.850
doing with the memory.

00:36.660 --> 00:39.200
So I'm going to do the sale code.

00:39.210 --> 00:42.600
So first sale begin.

00:45.130 --> 00:50.530
Right, and in the loop, I am going to do if.

00:51.910 --> 00:53.890
Take a look at the label.

00:55.760 --> 00:56.930
Is your return zero?

00:57.050 --> 01:09.190
So if we have data that was received in decision and going to the end data is serial that pass it.

01:09.880 --> 01:10.340
All right.

01:10.760 --> 01:13.810
So I get an integer, OK?

01:13.880 --> 01:15.350
Because this is what we expect.

01:15.350 --> 01:16.520
I get an integer.

01:16.940 --> 01:19.660
And I straight into this volume, though.

01:19.820 --> 01:23.660
Of course, what I'm going to do is also say that that.

01:25.040 --> 01:29.870
Time out with 10 milliseconds so we don't wait too long for this.

01:30.290 --> 01:36.260
OK, so if you don't understand everything here, please go back to the cellular section to practice

01:36.260 --> 01:38.000
more and which the clinicians.

01:38.450 --> 01:38.860
All right.

01:38.870 --> 01:44.210
And now this data before I do anything, I'm going to validate the data.

01:44.720 --> 01:50.930
Whenever you receive something from an external source, you want to validate the data because you don't

01:50.930 --> 01:51.100
know.

01:51.110 --> 01:53.390
Maybe I could send the value.

01:53.570 --> 01:56.120
Ten thousand, OK, if I send 10000.

01:56.150 --> 02:01.710
Well, the thing is that these data, this value is going to be used for the analogue right.

02:01.730 --> 02:02.170
Function.

02:02.200 --> 02:12.870
So we expect a value that is the data is greater or equal than zero and the data is lower.

02:13.190 --> 02:20.840
So let's say strictly lower than 256, which means 255 just for readability.

02:21.620 --> 02:22.250
And this.

02:25.810 --> 02:29.320
And OK, now we have validated the data.

02:29.800 --> 02:37.690
So what I'm going to do is say that print and then data, so I'm just going to validate that when we

02:37.690 --> 02:41.770
are at this point, then I will be able to do it from that.

02:42.460 --> 02:44.080
Right, Kate?

02:44.740 --> 02:46.120
Because we are in the loop.

02:46.750 --> 02:48.300
So I don't want to do it from that.

02:48.310 --> 02:48.610
Right.

02:48.610 --> 02:52.690
Somewhere where I'm not sure how often it will be updated.

02:53.150 --> 02:55.390
But no, let's run that first program.

02:55.390 --> 02:57.400
Something to see if it is activity.

02:58.800 --> 02:59.340
13.

03:02.390 --> 03:05.110
OK, let's open the sale monitor.

03:06.410 --> 03:12.930
Which has nothing for now, and we seen the value, let's say twenty three, I get twenty three and

03:12.960 --> 03:15.470
say I think zero zero.

03:15.470 --> 03:16.600
Two hundred fifty five.

03:16.940 --> 03:18.160
Yes, that's the minimum.

03:18.170 --> 03:18.850
The maximum.

03:19.160 --> 03:20.510
Let's try minus one.

03:21.180 --> 03:22.310
OK, we have nothing.

03:22.790 --> 03:24.890
Let's try 256.

03:25.760 --> 03:30.620
We have nothing in any other value above two hundred fifty six.

03:30.620 --> 03:31.940
We would have nothing.

03:32.210 --> 03:40.090
So we only write it, we sell the print and then when we have received the data and the data is valid

03:40.100 --> 03:40.490
ok.

03:41.740 --> 03:49.570
So we know we can do it from your right, OK, and remove Sayle that print, Ellen.

03:51.080 --> 03:59.180
Here we are sure we are not going to rate it at full speed, and I did that to verify the code, actually,

03:59.180 --> 04:05.780
because when you send some code, maybe it's competing correctly, but maybe you have made some little

04:05.780 --> 04:09.770
mistake and then the behavior is not what you would expect.

04:10.220 --> 04:14.730
So by doing this, you are sure the behavior is correct, so it's not right.

04:14.750 --> 04:20.750
So I'm going to write an address, let's say altoist 350.

04:21.760 --> 04:27.880
I'm going to write the data and it's better not to just how it could be, otherwise what I can do is

04:27.880 --> 04:29.230
create a define here.

04:30.370 --> 04:34.360
So define EPROM and race.

04:35.310 --> 04:43.520
Max, let's see, brightness or intensity of the same thing and let's say three hundred fifty, OK,

04:43.950 --> 04:45.660
and I'm going to put that here.

04:46.350 --> 04:48.990
So the name is quite long but quite explicit.

04:49.620 --> 04:54.840
And of course, because I use EPROM, I need to do include.

04:56.420 --> 04:57.980
EPROM notes H.

04:59.190 --> 05:05.540
All right, so now we have commercialized the cell communication and whenever we send some data, so

05:05.610 --> 05:14.010
some number to the from the computer, we're going to validate that data and write it in to the.

05:15.120 --> 05:20.970
So let us handle the energy and the potential to bring all that.

05:23.100 --> 05:30.150
Well, let's hear Define Energy Bill, which is AFSA 10.

05:31.930 --> 05:33.490
Define what lunchmeat.

05:38.330 --> 05:44.690
In which is a two and in the void, he said, I'm going to do.

05:46.510 --> 05:47.560
Incommode.

05:50.410 --> 05:50.800
In.

05:52.870 --> 06:03.730
But I do need to set a pin mode for the put on the pin because as default, this is an input pin and

06:03.730 --> 06:04.480
then in the loop.

06:04.630 --> 06:09.160
So we have our action one which is checking the sale.

06:09.490 --> 06:11.710
So this is going very fast.

06:12.750 --> 06:19.320
And then I can do my sergant action and I'm going to read the value from the put on Schmitter and also

06:19.320 --> 06:25.440
because the value from the potentiator is from zero to one thousand twenty three, I would need to divide

06:25.440 --> 06:27.020
this value by four.

06:27.300 --> 06:32.370
But we can have a value between zero and two hundred and fifty five for the analogue.

06:32.370 --> 06:32.790
Right.

06:32.790 --> 06:44.190
Function them directly going to the bait and the ripeness is equal to analog read on the potential to

06:44.190 --> 06:44.490
be.

06:48.030 --> 06:50.190
It divided by four.

06:51.660 --> 06:59.820
I read this to give the value between zero and one thousand twenty three, I divide by four and then

06:59.820 --> 07:06.630
I put this directly into the brightness viable, which is a bit dated.

07:06.960 --> 07:15.270
OK, but instead of just putting this inside a viable and then completing this, I just put everything

07:15.270 --> 07:18.720
together and then we have analogue.

07:19.770 --> 07:20.370
Right.

07:21.240 --> 07:25.410
And then with the added brightness.

07:27.520 --> 07:37.010
But the thing we want to cap the volume so we will need to have somewhere a max brightness volume.

07:37.330 --> 07:43.810
OK, I'm going to create here, right, max brightness.

07:44.320 --> 07:49.430
So we have the available not initialized yet, but I'm going to use it here.

07:50.620 --> 07:52.410
So if ready.

07:53.910 --> 07:55.890
Right now, this is.

07:56.820 --> 07:58.620
Greater than the max.

08:00.180 --> 08:05.100
Brightness, what we are going to do is to see that the energy.

08:06.520 --> 08:10.780
So the brightness is equal to the max brightness.

08:11.890 --> 08:15.090
And this is how you can cut a volume.

08:15.660 --> 08:20.180
OK, you check if the value is greater than the maximum.

08:20.860 --> 08:24.790
If yes, then you just say that the value becomes the maximum.

08:25.480 --> 08:29.020
So this can be very useful in many different applications.

08:29.480 --> 08:35.260
So what do we do here is we check the brightness from the bottom and then we make sure it's not greater

08:35.260 --> 08:41.720
than the maximum or else we change it and then we can give it as a parameter for our function.

08:42.160 --> 08:46.450
And now let's actually see how to set this value here.

08:46.810 --> 08:55.090
So first here, when we actually do this, when we write to the memory, we can also do Max.

08:57.130 --> 09:01.820
Rottenness is the data, so the validated data.

09:01.850 --> 09:02.190
OK.

09:03.690 --> 09:11.310
Once we validate the data, we save it into the EPROM, but we also set it in our code so that the value

09:11.310 --> 09:14.640
we send to the sale will be used here.

09:15.270 --> 09:17.370
So that is during the execution of the program.

09:17.550 --> 09:22.490
But now how to initialize the valuable when the program starts?

09:23.360 --> 09:23.590
Well.

09:24.570 --> 09:26.230
So we are going to initialize it here.

09:26.640 --> 09:27.150
Max.

09:28.510 --> 09:29.260
Brightness.

09:31.090 --> 09:33.610
Is equal to EPROM.

09:35.080 --> 09:37.810
Read from this.

09:39.950 --> 09:47.680
Otherwise, OK, so by using a defined here, I can use the name here of the constant here and here,

09:47.900 --> 09:54.020
so if I want to change the address, I just need to change it here and I can be sure that it would not

09:54.020 --> 09:55.220
affect the program.

09:55.910 --> 09:58.340
OK, so here we have negative brightness.

09:58.700 --> 10:05.810
We said it directly first from the employment rates or the value that was stored previously and then

10:05.810 --> 10:07.160
during the program execution.

10:07.730 --> 10:10.090
We can update this at any time.

10:10.100 --> 10:14.690
So we updated in the code and we also added eat into it from memory.

10:14.720 --> 10:21.110
So the next time we start the program again with this line, we are going to get the last value that

10:21.110 --> 10:30.920
we have set here with this and pass it and note that we need to also handle the case if we haven't written

10:30.920 --> 10:32.040
in the April yet.

10:32.080 --> 10:36.700
OK, so far we haven't written in the three hundred fifty address.

10:36.710 --> 10:45.620
So what we are going to write here, maybe two hundred fifty five are also maybe zero and we don't want

10:45.800 --> 10:51.800
the next brightness of zero to start the program because this means here if it's zero.

10:51.810 --> 10:57.140
Well the analog rate we just sent is zero and LG will not be put on.

10:57.540 --> 10:59.300
What I'm going to do is check if.

11:00.910 --> 11:02.530
Mike's Bruckner's.

11:04.230 --> 11:07.800
Is equal to equal to zero.

11:09.410 --> 11:11.120
Then I'm going to do Max.

11:12.750 --> 11:21.030
Bruckner's I'm going to set a default value, let's see, two hundred fifty five and instead of cutting

11:21.030 --> 11:23.910
it, I'm going to do you define.

11:29.240 --> 11:29.990
Brightness.

11:31.390 --> 11:35.610
Default, and it's a two hundred fifty five and let's put that here.

11:36.850 --> 11:40.910
OK, so this way we can change all the parameters directly from those two defined.

11:41.380 --> 11:41.730
All right.

11:41.770 --> 11:49.300
So for the first run, if what we read from the EPROM zero, then we directly change it, but we don't

11:49.300 --> 11:53.410
have zero as a default value and then everything will restart the program.

11:53.410 --> 11:56.930
If we have set a new value here, we're going to the new value.

11:57.490 --> 11:57.970
All right.

11:57.970 --> 11:59.770
And now let's upload the program.

12:02.110 --> 12:09.730
So as you can see here, this is on, but not at the max intensity, so this is just because it was

12:09.730 --> 12:11.580
in the middle of the potential meter.

12:11.920 --> 12:13.180
So I turn it.

12:14.280 --> 12:23.040
Off I go to the minimum and then I turn it on, you can see it goes to the maximum.

12:23.730 --> 12:24.810
Know what I'm going to do?

12:24.810 --> 12:26.730
I'm going to open the cell monitor.

12:29.000 --> 12:34.790
So this will restart the program, as you may know, and I'm going to set a different view, so let's

12:34.790 --> 12:39.120
say I send 60, I send 60.

12:39.140 --> 12:47.750
You can see the brightness is lower than before, OK, because the max brightness is 60, OK, they

12:47.750 --> 12:55.360
can go down to zero and then they can go up, but it will cap at 60.

12:55.490 --> 12:58.460
OK, if I put, let's say, 200.

12:59.800 --> 13:02.150
It the brightness has just increased.

13:02.620 --> 13:06.710
I can go up to two hundred or so as low as zero, up to 200.

13:07.270 --> 13:12.010
Let's put a little bit at the brightness.

13:12.010 --> 13:14.290
Not maximum brightness is eight.

13:14.320 --> 13:20.500
So from zero eight in any value after eight, we just stay at 80.

13:20.530 --> 13:22.730
OK, so I can tend to put on shmita.

13:22.780 --> 13:26.010
The brightness will not increase after a certain point.

13:27.350 --> 13:29.090
And no, let's restart the program.

13:29.930 --> 13:32.370
I'm going to press on this reset button here.

13:33.950 --> 13:40.460
The program has restarted and oh, well, the max intensity is still the same as before.

13:41.360 --> 13:47.030
OK, it is 80 now, let's say, but two hundred forty.

13:48.230 --> 13:49.410
OK, much brighter.

13:50.060 --> 13:51.530
I can.

13:52.700 --> 14:01.060
Or is it the program and it's still 240, OK, can go down and can go up, it's tribal for a very small

14:01.060 --> 14:08.670
value, 20, OK, so the max is 20, I can go to zero, etc., but it's going to zero.

14:09.070 --> 14:10.300
Let's restart the program.

14:14.000 --> 14:20.550
And now let's go up and I can only go up to 20 in the morning.

14:22.140 --> 14:26.610
All right, and that's the end of the security as well as the section on April.

14:27.180 --> 14:31.030
So the important thing is make sure you don't write at full speed.

14:31.170 --> 14:34.740
OK, but if you correctly test your program, you should be fine.

14:34.920 --> 14:40.950
And as you can see, that's a quite powerful way of setting a default value and keeping this default

14:40.950 --> 14:43.850
value for multiple runs of your program.
