This is the step 11 and also the final step of the final project of this course.
So the last thing we want to do now in our project is to use the photoresistor to get the current light.
And with that current light and the current luminosity, what we are going to do is to so we are going
to put on the green energy what we can call the light.
And we are also going to add a new mode to the LCD screen so we can print the current value of the luminosity.
So this can be useful.
This is an added functionality.
Get to the circuit and the project.
This can be useful.
Let's say you have the robots and you detect that when the light is too low, then you are going to
automatically increase the light with some energies.
For example, just like you will have automatic lights on a car and not also here.
Not to confuse, but the ultrasonic sensor on the photoresistor are two different things.
OK, the light that you set with the photoresistor will not help the ultrasonic sensor because the ultrasonic
sensor will send some ways that do not require any light.
OK, so the light here is just to say, OK, let's use some light so we can see the robot, let's use
some light.
So, well, let's see if you have a camera.
If you add a camera in the robot, you can also help the camera by providing a good lighting.
All right.
So let's get started with this.
So first, I am going to set up the photoresistor and let's put so we have all been here.
Let's put it here.
For example, define for to operate the store pin, which is a zero.
And I'm going also to define here the light and pin pin number 10, make sure this is a pin which has
a B.W. and functionality.
So here we go in the set up in the set that we don't need to initialize the European because we are
going to use it as an analog inputting, but we need to initialize spin mode like editing to output.
Let's actually put that.
With the other hand, it is here.
OK, that's it for the initialization now in the loop, so we have our different functions, so we need
to ask ourselves, do we want to only check the photoresistor when the application is locked or when
the application is not locked?
Or in any case and actually it doesn't really matter.
Any case is fine.
We just want to continuously check the photoresistor, but actually with the rate of one hundred milliseconds.
So every 100 means we are going to update the light and update the LCD screen.
So I'm going to add.
OK, here we have I can if you up to the storm and cyclone last time.
That's the last thing, right, Luminosity?
Initialized to Amelie's and then unsigned long, let's see, breed luminosity.
DeLay is so let's say one hundred.
That would be fine.
OK.
Now in the loop, so I'm going to do I'm going to go at the end of the loop after we do everything OK,
because it doesn't really matter.
I'm going to do if thank no minus last time.
Great.
Luminosity, if this is greater than the.
Great luminosity.
Delate.
What we do is always we add the delete to the last time.
And now we can get so into luminosity.
We can directly get the remnants with analog.
Read from the photo register.
And then we are going to do two things.
Set light green on city.
So let's create two functions to do that.
I'm going to create in here above the void setup to void, let's say set light.
Read from Luminosity.
Within the INS, because this is a value between zero and one thousand twenty three, and I'm going
to compute the brightness flexibile because the brightness for the analog verite function will be between
zero and 255 brightness.
Is equal to so we have already done that before, 255 minus luminosity divided by four, because we
need to scale down the value from one cell twenty three maximum to two hundred fifty five maximum.
So we need basically to divide by four and we need to also invest.
OK, so the more luminosity, the lower the brightness.
And then unallowed bright light and then so that's why I told you it's important to use a pillow U.N.
team because we use analogue, right?
Brightness.
OK, we have the first function here and let's create another one void print luminosity on LCD int it.
And actually, to print that on the screen, we need to check two things we need to check if this is
not logged.
So if exclamation mark is locked and if the LCG mode is actually the mode for the luminosities.
So we need to create a new mode for the luminosity.
So let's create here.
We have LCD distending settings and different LCD mode, luminosity to.
OK, so let's use that now to just.
It if the mood is luminosity and then we're going to go out to toggle it.
So if it's locked, we don't bring that, we print that warning, the error message, if it's not locked
and the mode is the correct mode, we print the LCD set ghiorso zero zero.
And Brent.
Luminosity.
And then actually print up the viral value we have it let's add a few extra species just in case.
All right, so we should have the 16 characters and that's it for the two functions, so I'm going to
call them from the look.
A satellite with luminosity that we get here and.
Let's go back to Princeton University and City.
We luminosity.
Let's not forget the semicolon.
So what do we do here?
We get the city, we set the light and we print on the LCD.
And of course, when we go to this auction, we check the vault.
So now we need to change the LCD mode.
We need to add to handle this mode or so when we do the toggle LCD screen.
OK.
So we have case distance settings and in case.
Luminosity.
So you can see now why I used the switch.
Let's just break and let's do.
Entity mode is now equal to.
And here I'm going to put it here.
So if his distance would change to settings, if it's settings would change to a living entity, if
it's luminosity would change to distance again.
And the thing is that No.
As you can see here, we have to balance, we are up and down, so before that, it was not that important
because we only had two votes, but now we have mode's one, two and three, which means that Wildeblood
that we could say we want to go to the next move and with the Burrendong, we want to go to the previous
smoke.
So if you're in mode two, for example, and you press the button up, you go to three.
But if you press the button down, you go to mode one.
So let's add here, let's make it simple.
Let's add a boolean next.
If the boolean is true, it means the next one.
If the word is false, it means the previous one.
So not in the mood is currently distance.
What I'm going to do, I'm going to use the one line if next.
So next is a boolean.
So this we can just test it.
OK, three, be true or false.
If next then we go to sitting's and then Calon.
If not, we go to Leninists, which is the mode number three.
So when we are in mode, the first mode next we go to the second mode.
Previous we go to the mode.
So the last one OK then aelfwine mode settings and we have the next, next, then we go to Luminosity.
But if it's previous we go to distance.
And then when we are in Luminosity, if.
Next, then we go to distance, OK, because there is nothing after leaving the city, we go back to
distant.
Else, we go back to settings here.
OK, and you can see now you can add as many GS as you want in the switch, that would be very easy
to handle.
OK, just do next and then the next one, the previous one you can choose in which order you are going
to navigate through the different modes of the exit.
And of course, the default is always going to the default in case we have said something that is wrong.
And because we have moved next, now we need to actually use.
A perimeter.
That's where we have an arrow, something to do through here and force him to go LCD screen through
for next Fox for next, which means produce one.
All right.
Let's just verify and name it as final projects that even the last one.
Don't complaining and no.
So just a very quick recap of what we have added here, so we have added the photoresistor reading here,
we finally agreed.
We also the time functionality to read every one hundred milliseconds, which should be here.
And then what we do is we set light energy, so we use analogue right for the energy to increase the
brightness when the luminosity decreases and then we print the luminosity on the LCD when we are in
the LCD mode, luminosity.
And of course, because we have added one mode, we have added this mode also to the toggle LCD screen
function.
OK, so we can toggle between the different modes using two older going to the next one, all the previous
one from the button up and down from the infrared remote control.
So now you can see once you have set up the different functionalities and components, you can create
a much more complex behavior and you don't need to write thousands of lines of code.
And now let's finally upload that, which is the final product, which is the complete project.
And let's see if everything is working.
So you can see here we have the distance in centimeters and now I'm going to press on down button.
So I'm going to the settings, which is the next mode I press again.
I go on the luminosity and I can see the luminosity as well as the energy here, which is both on OK.
And if you try to lower that immunity, you will see the brightness increase and you increase the luminosity,
the brightness will decrease.
So no angle in that order.
So distance settings, Leninists and going to the other down button and I'm going under the reverse
order.
OK, luminosity settings, distance.
OK.
And well, sometimes it may happen that it's too sensitive, so you are going to press twice on the
same button, so just make sure that you correctly press on the button.
And, of course, again, that you have a good battery inside the remote control and, well, that is
the end of the final project.