This is the number 10 of the final project, and in this step, what we are going to do is to be able
to toggle between different screens on the LCD screen.
OK, so the default one we have is to print the distance and then to bring someone in, for example,
when the application is not locked, of course.
And what we want to do is maybe to bring something out.
So what we are going to print is the instructions to resist to the default settings.
And when we are in that screen, we are going to be able also to reset the default setting using the
remote controller.
So in this that we are going to create some mode for the LCD so we can toggle between different mood
and different displays using the remote control.
And then for the second mode, the reset setting mood, we're going to add the action to reset the settings.
So let's start and let's add some.
So let's do that here.
So kidlets argument.
Distance unit, and here it's a recruitment.
LCD mode, so let's define acidy mode.
Distance, which is the default one, that's zero defined and said.
Moad Sitting's.
One and actually in the next step, we are also going to add another mode, so we have to and let's
create here in LCD mode is equal to the estimated the distance.
So quite similar to what we have done with the distance.
OK, that's the same thing.
Now I'm going to.
So let's find the angle I command.
I'm going to add a new function void toggle.
LCD screen.
And I'm going to use a switch here, because for now we have two modes, and the next step I'm going
to add another mode or switch will be quite appropriate.
You switch with the exiting mode.
And then we're going to take the case LCD mode, this tends to do and then break and in the case LCD
mode.
Settings to do and break and the default.
So what do we want to do?
We want to simply modify the LCD mode.
So if the LCD mode is distance, we do LCD mode.
Become settings, if not, the mode is settings, we do LCD mode becomes.
Defense.
And the default one, basically, if it's none of the two, which should not happen, but if it happens,
which we do, we simply LCG mode is equal to sitting to distance.
We set it back to the default one.
So here we have the default.
OK, that's the same.
So he, as you can see, another simple state metion with a switch and I have used the switch, so when
we add another mode in the next step, that will be super easy to modify.
And I'm going to call this.
So we can toggle between different screens.
We're using the button up and button down to go to the left side, to the next screen, up to the previous
one here, because we only have two screens.
Well, we don't need to worry about that for now because the previews and the next screen is the same
if you have two screens.
So I'm just going to toggle the screen whether we use up or down, OK, but we call the function with
the same behavior.
So now that we have toggled between the stage where we need to actually use that state to do something.
So if we go back to our function, print distance on LCD.
So first we check if it is locked, then we do this.
So that is always going to be the case.
OK, the locked behavior will always overwrite any other behavior.
And then else I'm going to add as if LCD mode.
Is equal to.
And see mode dist..
With two equals, of course, so I'm only printing this if we are in the distance mode, OK?
And if not, so if the application is not locked and not in the distance mode here on the print distance,
we just print nothing.
OK.
And now what I'm going to do here is, well, when we switch to the mode settings here, I'm going simply
to add here, if that's the mode is equal to the mode settings.
Then I'm going to print the instructions to reset the settings, so let's say LCG got set, just saw
with zero zero and then and see that print, that's a price of two and few spaces.
And she said Couso zero one Ellsinore print reset settings.
So I just printed the restriction on two lines.
OK, so basically you see enough when we toggle the LCD screen, if we arrive at the mood settings.
I'm going just to print that and that's it, and now because it's in the mode settings, we are not
going to print anything else in the print distance on Esseily.
And why are you writing this here?
Because, well, simply we just need to write this once.
I could have had it here.
And as if LCG mode settings that would be called also whenever we want to print the distance on Elsley,
but that's another functionality and that will print this many times per segan.
And we don't need to do that.
We just need to print it once when we said the modem.
That's one thing I'm going to do here.
It's also the entity that clear, OK, after I change the mode and is going to clear whatever is on
the LCD screen, though, not if the mode is distance, we bring the distance with the other function.
Now, if we go to settings, we clear, we print press on us to reset the settings.
OK, then we are going to see how to do this section and then we toggle again.
We are going back to the distance mode and in that case we clear the screen.
We don't enter this and then we can continue to print the distance as we did before.
And of course, if we ever lock the application, this will overwrite anything else that you try to
print.
And now that so let's say that we are in this screen, we are in the settings screen, which is seen
press on off to reset settings, so the above is the button here.
So I'm going to create a new function here, void reset settings.
Let's say to.
So here we have only one city that we can modify is the distance unique and the default is sentiment.
But as an improvement for this final project, you could think of adding in many different settings,
for example, doubling bright for the year.
And it is the threshold to detect that an obstacle is on the way.
So you could add many different settings, OK, that you can change, for example, with the remote
controller and save to EPROM.
And then when you call reset settings to default, you just reset all the settings to, well, to default.
So here I'm going to check first if.
So when we call that function from the handle, I recommend mean, to check if the ELSLEY mode is equal
to LCB mode.
Sitting's why I do that, because we are only going to be able to reset the settings when we are on
the settings screen.
OK, so if you want to reset the settings, you have to step first.
You go to the screen and then you press off, OK, to, for example, to avoid that, you just reset
the settings at any time.
So to reset, I'm going to do distance units, set it back to distance.
You need centimetres because I change the distance unit.
I need also to do it from that.
Right.
We've become let's find this is the ultra distance unit.
And these tensions.
So if you have any other parameters of any other settings, you or is it then here and then what I'm
going to do, I'm going to print a confirmation message on the AC.
So let's do LTT clear and then SCD that sits.
Tiso zero zero And she that print with let's say sitting's have.
And in a city that sits just zero one.
Nancy DePrince.
Settings have been or is it?
I don't add extra species here because I just cleared the screen before, so no need to add them and
actually here because they clearly screen these, I could add them on.
That's not the problem here.
And I'm going to call that function from the IT when we press on the button.
All right, it seems to me that the good is good.
Now I'm going to verify and see it as a final project.
Step number 10.
And a quick recap here, so when we press the button up button down on the remote controller, we call
the toggle and discreet, which is here.
So now we have set an LCD mode, which is distance all settings.
So when we talk on the screen, we are going to change the mode.
And then depending on the movie, we are going to print different things on the LCD.
So if the mode is distance, we print the distance as before.
If the mode is settings, we print the message and instructions so we can present the settings, OK.
And of course, if the application is locked, this will of the right.
Any other behavioral.
Now, when we are on the LCD mode settings, if we price on the off button, we call the reset settings
to default, and so we see that we are actually in the correct mode to do that.
And in that case, we just reset the settings and we print a confirmation message.
And also one thing and going to the one small additional thing I'm going to do is when I unlock the
application, I'm also going to the LCD that clear because now we have different modes.
So if we have the distance mode, it's going to continue to print the distance.
But if we are in the settings mode, because we just print the setting text once, we need to clear
to make sure that we don't get the error message if we were in the settings mode.
So now let's upload code.
So the application is running as expected, normally with the default behavior, which is to print the
distance and you can see here we print in inches.
OK, that was the previous settings, the regular distance unit that I have set.
And when I started to program, it was retrieved from the from memory.
So what I'm going to do, I'm going to press on the button here the button Ildong to go to the different
modes of the LCD.
So this is the other mode where you can see press on off to reset settings so I can toggle between the
distance and this sitting mode.
Now, in this mode, I can just press on the off button and you can see settings have been there.
Is it if I go back.
So using the Ildong or you can see now I have the distance in centimeters, not in inches.
So you can see that all the default settings.
So we just have the distance you need.
All the default settings have been reset.
And of course.
Well the thing is that if you have an obstacle, it still overrides everything and you can't well,
you can't change the screen, OK?
The only way is to press on the play button to unlock and then you can continue to do whatever you want
with the screen.
All right, and that will be the end of this step, and as you can see, that can be quite convenient
to switch between different screens for the LCD to bring a different kind of informations, all different
kind of actions.