WEBVTT

00:00.210 --> 00:06.380
This is the solution of the previous activity where you need to create a small traffic light system,

00:07.170 --> 00:09.510
so we have three entities.

00:09.930 --> 00:16.170
The first thing we are going to do is to initialize it is to create a constant and then initialize.

00:16.180 --> 00:20.300
Then we build mode and then we are going to write the application code.

00:20.790 --> 00:23.380
So define eddied.

00:23.490 --> 00:29.090
So before we have written lipping, now we need to make the difference between the three entities.

00:29.100 --> 00:30.900
So I'm going to write the one.

00:32.280 --> 00:44.050
In this has been number 12 and then define added to PIN, this has been number 11 and define any three

00:44.730 --> 00:46.640
in this has been number 10.

00:47.460 --> 00:49.090
So the first one is the right one.

00:49.140 --> 00:57.150
Then we have the yellow one and then the green one, if you want, as an alternative, meaning you could

00:57.150 --> 00:58.150
name them, for example.

00:58.230 --> 00:58.620
Right.

00:58.620 --> 01:01.800
And Dippin Yellow and Green Arrow Dippin.

01:02.370 --> 01:03.930
But here that will do.

01:04.140 --> 01:09.180
And if we want to change the decal off our specific pin, we don't need to actually change the name.

01:09.750 --> 01:16.410
So we have our three define here in the setup and going to do in mode.

01:16.830 --> 01:25.630
We've added one in and out, so we set the mode as an output.

01:25.720 --> 01:31.140
People can agree to copy this twice for a two and three.

01:32.790 --> 01:38.570
So now all the scenes are set to output mode for digital.

01:39.060 --> 01:45.960
I'm going also to initialize all the states for all the pains to know, OK, well, just in case we

01:45.960 --> 01:46.530
are sure.

01:46.560 --> 01:53.510
So digital by just in case we are sure that all the ads will be pulled up.

01:54.250 --> 01:54.760
No.

01:55.410 --> 01:55.750
A.

01:57.360 --> 01:58.710
Into also be.

02:00.070 --> 02:01.840
And two entities, three.

02:03.660 --> 02:10.830
So now the initialization is complete, all the pins are set up to output mode, and we will no state

02:11.370 --> 02:19.710
and no in the loop function, we are going to first go around the red area, OK, and keep it on for

02:19.710 --> 02:20.760
three seconds.

02:21.300 --> 02:23.340
So digital.

02:24.300 --> 02:24.840
Right.

02:25.620 --> 02:29.520
And one thing I.

02:29.760 --> 02:33.480
OK, and keep it on for three, six days a week.

02:33.600 --> 02:35.310
Three hours.

02:36.330 --> 02:39.870
After that, I'm going to put on the green.

02:40.900 --> 02:42.040
And so.

02:43.080 --> 02:51.150
Digital rights, LSD, the green LSD, the three teen with high.

02:52.050 --> 02:58.140
But what I also need to do is to pull off the digital rights.

02:58.410 --> 03:03.540
And one thing is the power of the parade, OK?

03:03.870 --> 03:06.910
Because otherwise both entities will be forgotten.

03:06.940 --> 03:12.150
OK, if I use digital right here with high on it one thing, then it's still high.

03:12.180 --> 03:13.600
So I need to put it to low.

03:13.740 --> 03:19.680
OK, the first we're on the red alert and then wait three seconds.

03:19.870 --> 03:29.060
Then we were off the road and we were on the green and then we wait for another three siggins OK.

03:29.520 --> 03:33.030
Or the second if we keep the green for three seconds.

03:34.080 --> 03:38.730
And then what we do is we put on digital right.

03:39.240 --> 03:41.880
With energy to in.

03:41.930 --> 03:42.870
We on.

03:44.190 --> 03:52.410
The signal for one signal, but actually here, that's the same thing with the green educated green

03:52.410 --> 03:53.820
energy, we will answer.

03:53.850 --> 03:57.360
We need to Polaroids of the digital.

03:59.080 --> 04:02.040
Right, and three.

04:03.880 --> 04:05.830
In we've know.

04:06.870 --> 04:10.440
And then we wait for one single.

04:12.320 --> 04:19.580
All right, and then after this one segment, then we finish the look, we come back here and here we

04:19.670 --> 04:21.320
go on the editing.

04:22.130 --> 04:30.650
But again, at this point, if we pull on the yellow alley here, then it's still on when we arrive

04:30.660 --> 04:30.960
there.

04:31.220 --> 04:33.560
So we need to pull it off.

04:34.130 --> 04:38.870
Digital rights so that the two.

04:40.110 --> 04:41.280
In the.

04:42.720 --> 04:44.640
All right, to remove this.

04:45.970 --> 04:56.260
So to recap, first we pull up on the right and we pull off the yellow one, then we wait three seconds

04:57.400 --> 05:05.200
after three seconds the green and will be on and the red and you will be pulled off it for three more

05:05.200 --> 05:05.800
seconds.

05:05.800 --> 05:08.510
And then it's time for the yellow and green.

05:08.800 --> 05:16.370
And of course, we pull out of the green and then we once again and continue and go back again.

05:16.870 --> 05:19.120
And now let's applaud the program.

05:19.120 --> 05:22.590
OK, let's limit activity.

05:23.600 --> 05:24.020
I.

05:26.740 --> 05:35.860
And I can see first the red and then the green and then yellow for Walsingham, right for three seconds,

05:36.610 --> 05:42.610
green for three seconds, yellow for once again and then all over again.

05:43.600 --> 05:47.820
And you have successfully creeky your first traffic light system.

05:48.250 --> 05:55.270
And just one thing with the code here to make it maybe simpler to read and maybe also simpler to modify

05:55.270 --> 05:56.120
in the future.

05:56.650 --> 06:01.840
So here we just modify any one and two and then one in three and then two and three.

06:02.410 --> 06:06.710
What we could do is also see for the first time digital.

06:07.150 --> 06:10.570
Right, any three in low.

06:11.040 --> 06:16.820
So that is quite redundant because we already said it's too low before, but then we have one, two

06:16.820 --> 06:17.290
or three.

06:17.290 --> 06:19.390
And then we see we have high, low and low.

06:19.780 --> 06:23.410
And then what we can do is aim for a second block.

06:24.740 --> 06:29.090
One, two, three, with low, low, high, and then we are missing.

06:30.810 --> 06:33.400
And one here, OK?

06:33.490 --> 06:40.530
And as you can see, it's maybe more readable, OK, every time we said digital right for the three

06:40.710 --> 06:46.770
pins, OK, but just here you can see first it's high, low, low and then low, low, high and then

06:46.770 --> 06:48.670
low, high, low, low.

06:48.690 --> 06:50.160
This way it's more reliable.

06:50.160 --> 06:56.830
And maybe if you want to change the behavior, you will more easily avoid to make some mistakes, OK?

06:57.300 --> 07:03.420
The best code is not necessarily the code with the less lines in it, OK, it's best to have shorter

07:03.420 --> 07:08.610
code, but any time you should put more importance on the reliability of the program.

07:08.640 --> 07:12.860
So if this means a few more lines, then just add those few lines.

07:13.290 --> 07:13.710
All right.

07:13.710 --> 07:15.070
And that's the end of the security.
