WEBVTT

00:00.080 --> 00:02.420
And here is yet another activity.

00:02.420 --> 00:05.720
And with this we will finish this section on Gpio.

00:06.020 --> 00:11.660
So the goal of this activity is to make the code that we did in activity six.

00:11.660 --> 00:15.200
So we're just going to take the same code we did in the last video.

00:15.230 --> 00:18.710
We're going to take this code and we're going to make it more dynamic.

00:18.710 --> 00:24.260
So the goal is to be able to use this code for any amount of LEDs.

00:24.260 --> 00:25.880
So we have three LEDs.

00:25.880 --> 00:28.490
But now what if you have five LEDs.

00:28.490 --> 00:32.450
You see that with this you will need to modify the code a lot.

00:32.450 --> 00:35.090
And you will need to add a lot of lines.

00:35.120 --> 00:35.450
Okay.

00:35.480 --> 00:41.480
So if you want to have the same code working for two LEDs or five LEDs, well you will need to do some

00:41.480 --> 00:42.410
improvements here.

00:42.410 --> 00:46.400
So for this activity number seven we will not add any hardware.

00:46.400 --> 00:48.980
We will not add any new functionality.

00:49.010 --> 00:52.400
We will just work on the existing code and improve it.

00:52.430 --> 00:56.570
What I will do is I will just uh well you have the activity six.

00:56.600 --> 01:00.590
I'm just going to save it as activity seven.

01:01.370 --> 01:01.940
All right.

01:01.940 --> 01:03.830
So that's the new activity.

01:03.860 --> 01:06.560
We're going to start from the same code and improve it.

01:06.560 --> 01:08.450
And what will we do.

01:08.480 --> 01:15.720
Well here we will work with lists So I have my three LEDs and I'm just going to start with this.

01:15.720 --> 01:17.850
I'm going to give you that tip.

01:17.880 --> 01:21.120
You can start an LED list like that.

01:21.120 --> 01:24.720
And in this you will put three variables.

01:24.720 --> 01:27.570
Actually you will not just put integers or strings.

01:27.570 --> 01:31.020
You will put actual variables here that we have created before.

01:31.020 --> 01:34.890
So led one LED two, LED three.

01:34.920 --> 01:35.250
All right.

01:35.280 --> 01:36.780
You create the three LEDs.

01:36.780 --> 01:39.750
You put them inside a list.

01:39.750 --> 01:41.520
And then what can you do in this program.

01:41.520 --> 01:45.060
Well first of all you see that we initialize all LEDs.

01:45.060 --> 01:47.970
So we set the initial state to off.

01:47.970 --> 01:49.230
So turn off the LEDs.

01:49.230 --> 01:51.840
You can start by well using this list.

01:51.840 --> 01:58.350
And with a for loop, you can go through each element of the list and turn off the LEDs.

01:58.350 --> 02:01.410
Then we will keep this LED index.

02:01.410 --> 02:08.100
And we will also keep the last here two lines of the code okay, so when the button is pressed we will

02:08.100 --> 02:10.470
call the switch LED function.

02:10.470 --> 02:14.040
But there will be some work in this function.

02:14.070 --> 02:14.460
All right.

02:14.460 --> 02:21.960
So instead of saying zero, one two etc. we want to have something that's more dynamic.

02:21.960 --> 02:28.470
So the biggest part of the challenge is to find out what to do here so that we can work with this list.

02:28.470 --> 02:35.430
And basically for each index, we want to turn off all LEDs and turn one only one LEDs.

02:35.430 --> 02:37.290
So that's what you need to implement here.

02:37.290 --> 02:43.110
And for this you will need to know actually the length of the LED list.

02:43.110 --> 02:45.480
So you will need to get that into your program.

02:45.510 --> 02:47.520
I'm just going to give it to you here.

02:47.550 --> 02:48.930
I'm just going to write it here.

02:48.930 --> 02:54.720
If you want to get the length of a list, you can do l e n Len.

02:54.750 --> 02:58.980
You can see the syntax highlighting of for example LED list.

03:00.390 --> 03:06.660
So if I would just print this with that list it will return three because we have three elements.

03:06.690 --> 03:06.960
All right.

03:06.960 --> 03:12.120
So this is a function we're going to use in the solution that I haven't talked about before.

03:12.120 --> 03:13.500
So I give it to you now.

03:13.500 --> 03:16.710
And well I will see you in the next video for the solution.

03:16.710 --> 03:22.170
You might feel a bit lost now I know it's definitely a bit more challenging, but try to do as much

03:22.170 --> 03:23.250
as possible, okay?

03:23.280 --> 03:24.900
Try to find solutions.

03:24.900 --> 03:31.020
Try to find ways to solve this problem, and then you can watch the solution and maybe also try again

03:31.020 --> 03:32.160
in a few days.
