This is the solution of the previous activity where you need to create a small traffic light system,
so we have three entities.
The first thing we are going to do is to initialize it is to create a constant and then initialize.
Then we build mode and then we are going to write the application code.
So define eddied.
So before we have written lipping, now we need to make the difference between the three entities.
So I'm going to write the one.
In this has been number 12 and then define added to PIN, this has been number 11 and define any three
in this has been number 10.
So the first one is the right one.
Then we have the yellow one and then the green one, if you want, as an alternative, meaning you could
name them, for example.
Right.
And Dippin Yellow and Green Arrow Dippin.
But here that will do.
And if we want to change the decal off our specific pin, we don't need to actually change the name.
So we have our three define here in the setup and going to do in mode.
We've added one in and out, so we set the mode as an output.
People can agree to copy this twice for a two and three.
So now all the scenes are set to output mode for digital.
I'm going also to initialize all the states for all the pains to know, OK, well, just in case we
are sure.
So digital by just in case we are sure that all the ads will be pulled up.
No.
A.
Into also be.
And two entities, three.
So now the initialization is complete, all the pins are set up to output mode, and we will no state
and no in the loop function, we are going to first go around the red area, OK, and keep it on for
three seconds.
So digital.
Right.
And one thing I.
OK, and keep it on for three, six days a week.
Three hours.
After that, I'm going to put on the green.
And so.
Digital rights, LSD, the green LSD, the three teen with high.
But what I also need to do is to pull off the digital rights.
And one thing is the power of the parade, OK?
Because otherwise both entities will be forgotten.
OK, if I use digital right here with high on it one thing, then it's still high.
So I need to put it to low.
OK, the first we're on the red alert and then wait three seconds.
Then we were off the road and we were on the green and then we wait for another three siggins OK.
Or the second if we keep the green for three seconds.
And then what we do is we put on digital right.
With energy to in.
We on.
The signal for one signal, but actually here, that's the same thing with the green educated green
energy, we will answer.
We need to Polaroids of the digital.
Right, and three.
In we've know.
And then we wait for one single.
All right, and then after this one segment, then we finish the look, we come back here and here we
go on the editing.
But again, at this point, if we pull on the yellow alley here, then it's still on when we arrive
there.
So we need to pull it off.
Digital rights so that the two.
In the.
All right, to remove this.
So to recap, first we pull up on the right and we pull off the yellow one, then we wait three seconds
after three seconds the green and will be on and the red and you will be pulled off it for three more
seconds.
And then it's time for the yellow and green.
And of course, we pull out of the green and then we once again and continue and go back again.
And now let's applaud the program.
OK, let's limit activity.
I.
And I can see first the red and then the green and then yellow for Walsingham, right for three seconds,
green for three seconds, yellow for once again and then all over again.
And you have successfully creeky your first traffic light system.
And just one thing with the code here to make it maybe simpler to read and maybe also simpler to modify
in the future.
So here we just modify any one and two and then one in three and then two and three.
What we could do is also see for the first time digital.
Right, any three in low.
So that is quite redundant because we already said it's too low before, but then we have one, two
or three.
And then we see we have high, low and low.
And then what we can do is aim for a second block.
One, two, three, with low, low, high, and then we are missing.
And one here, OK?
And as you can see, it's maybe more readable, OK, every time we said digital right for the three
pins, OK, but just here you can see first it's high, low, low and then low, low, high and then
low, high, low, low.
This way it's more reliable.
And maybe if you want to change the behavior, you will more easily avoid to make some mistakes, OK?
The best code is not necessarily the code with the less lines in it, OK, it's best to have shorter
code, but any time you should put more importance on the reliability of the program.
So if this means a few more lines, then just add those few lines.
All right.
And that's the end of the security.