In this new activity, you will practice more with flask and the web server, and also combining this
with Gpio and this time with LEDs.
So your challenge is to choose which led to turn on from a web browser.
So from a URL here, depending on what you write in the URL, you're going to choose to power on or
to power off a certain LED.
So we have three LEDs.
We're going to choose which LED.
And then if we want to turn it on or turn it off.
All right.
So you can start from what we have written previously.
So here's the code that you can write.
I'm going to save it as activity 11 dot pi.
And I'm going to give you a few tips so you can get started.
So we are going to create a new route here okay.
So app dot route.
And then well I'm going to write the route first.
And I'm going to explain it to you.
So slash LED and then slash with angle brackets int LED number and then states slash and then int state.
All right.
That's the new route.
And then we're going to create a function.
So what is this.
Well we're going to start.
So slash LED.
And then you see we have here int LED number with angle brackets.
This means that we're not going to write this in the URL.
This is going to be replaced by an integer.
Okay.
So if you want to have dynamic URLs that you can write numbers or text or whatever inside, then you
can use this angle bracket with the data type.
And then the kind of the variable name that we're going to have inside our function.
So here when you write the URL you will do slash LED slash you will write a number and then slash state
slash another number.
And actually I need to finish this with the angle brackets.
All right.
So for example slash LED slash zero slash state slash one.
So provided that we start to count at zero zero is going to be the first LED.
And then if we get the state one it means we want to turn on the LED.
So we're going to turn on the first LED for the state.
To keep it simple, we can say that zero means turning off, one means turning on.
All right.
So you have this URL that I already gave you.
And then let's call this function switch LED for example.
And for that one we're going to receive parameters.
So the parameters is the ones that we define here.
So it's going to be called LED number.
And we know it's going to be an integer.
And then we have state okay that's the one here okay.
And then you can write of course the content of the function.
So what you will do we have three LEDs.
So what you can do is as we did previously in this course you can create a list.
So you create a list of LEDs.
Here you can initialize the first state.
And then in this function you will need to well you will need to first validate that those two are correct
numbers okay.
Because I could give whatever number I could give 5000 here I could give minus ten here.
So you want to first verify that the numbers are correct okay.
So that this corresponds to an index in the list and that this is either 0 or 1 okay.
So after you validate that then you can turn on or turn on the chosen LED.
All right.
And I will see you in the next video for the solution.