And here is yet another activity.
And with this we will finish this section on Gpio.
So the goal of this activity is to make the code that we did in activity six.
So we're just going to take the same code we did in the last video.
We're going to take this code and we're going to make it more dynamic.
So the goal is to be able to use this code for any amount of LEDs.
So we have three LEDs.
But now what if you have five LEDs.
You see that with this you will need to modify the code a lot.
And you will need to add a lot of lines.
Okay.
So if you want to have the same code working for two LEDs or five LEDs, well you will need to do some
improvements here.
So for this activity number seven we will not add any hardware.
We will not add any new functionality.
We will just work on the existing code and improve it.
What I will do is I will just uh well you have the activity six.
I'm just going to save it as activity seven.
All right.
So that's the new activity.
We're going to start from the same code and improve it.
And what will we do.
Well here we will work with lists So I have my three LEDs and I'm just going to start with this.
I'm going to give you that tip.
You can start an LED list like that.
And in this you will put three variables.
Actually you will not just put integers or strings.
You will put actual variables here that we have created before.
So led one LED two, LED three.
All right.
You create the three LEDs.
You put them inside a list.
And then what can you do in this program.
Well first of all you see that we initialize all LEDs.
So we set the initial state to off.
So turn off the LEDs.
You can start by well using this list.
And with a for loop, you can go through each element of the list and turn off the LEDs.
Then we will keep this LED index.
And we will also keep the last here two lines of the code okay, so when the button is pressed we will
call the switch LED function.
But there will be some work in this function.
All right.
So instead of saying zero, one two etc. we want to have something that's more dynamic.
So the biggest part of the challenge is to find out what to do here so that we can work with this list.
And basically for each index, we want to turn off all LEDs and turn one only one LEDs.
So that's what you need to implement here.
And for this you will need to know actually the length of the LED list.
So you will need to get that into your program.
I'm just going to give it to you here.
I'm just going to write it here.
If you want to get the length of a list, you can do l e n Len.
You can see the syntax highlighting of for example LED list.
So if I would just print this with that list it will return three because we have three elements.
All right.
So this is a function we're going to use in the solution that I haven't talked about before.
So I give it to you now.
And well I will see you in the next video for the solution.
You might feel a bit lost now I know it's definitely a bit more challenging, but try to do as much
as possible, okay?
Try to find solutions.
Try to find ways to solve this problem, and then you can watch the solution and maybe also try again
in a few days.