This is the solution of the previous activity where you need to get a string from the cell communication,
so you read the string and you print it on the LCD display screen.
So let's start with the cellular communication.
I'm going to initialized to you.
Say all that, begin OK, and then sell it time out with 10 milliseconds in the loop function.
I'm going to do if sale if the label is greater than zero.
So if we have received any data, we are going to put this into a string.
Text is equal to say you read string.
And we got the text, so that's pretty much it for the cell communication.
You don't need to do anything else.
You just take cell available and then read train.
Now, what I'm going to do is I'm going to create a function here, void print, use a text on display
with a string text as a parameter.
And here we are going to print the text on Etsy.
So then I can use this function here directly after I have read the string, I'm going to send it to
that function so I don't need to write the code of that function in the loop and know where our value
is complete for this activity.
OK, so we keep it minimal and then we have the functionality here in the function that.
All right, that's it for the sale.
No, let's initialize the liquid crystal display on the LCD screen.
So include.
Liquid crystal dumped H and then we need to do a bunch of defiance.
I'm going to do them here once again for this activity.
So Elsley up as.
Dean, which is a fine for me.
And C, d, e, d, which is a four, then define LCG before being which is number six and need to do
this three more times or so, the five, which has been number seven, the six which is PIN number eight
and seven, which is number nine, I got my six being set to correctly make sure you don't make any
mistakes and then I'm going to create so leaky.
Crystal LCD, I create these in global scope so that I can access the LCD screen everywhere in my program,
we first address.
Then in, then defore.
All right, I go to a new line to make it better and more readable, the five.
The six.
And D7 and that's it.
OK, our LCD is now here, and what I can do in the setup is the LCD begin 16 by two because this is
the hardware that we have.
Great.
So now everything is set up.
We receive the text from the sale.
Now we can use this function to print the text on SD and actually what are we going to do in that function?
So first we are going to validate the text.
OK, validate that it's not too long.
OK, after we do this, we set the cursor with a line zero one and then print text and let's start by
validating the text length.
So if text that length you have the length function, OK, which give you the length of the text.
Quite straightforward here.
This is greater than 16.
And what do we do?
I'm simply going to do this text is equal to text to log.
So if the text is too long, I just replaced the text with another text and this is the error message
that we are going to print.
OK, that is good.
Now, we said the cursor to line zero one, so let's do LCD notes, said Jesso.
So the column will be zero.
And then the line how to alternate between the lines with.
It's quite simple.
We are going to create a new viable here line.
Let's initialize it to zero and going to put it there.
So first time it's zero and then we are going to toggle this.
If it's zero, we set one.
If it's one we said to zero.
OK, so right now here I'm setting the closer to column zero and the cursor line, which is either zero
or one.
And then I can do that print.
Let's do that, actually, let's put that here and see what Prince.
Text, so we are printing the text that is already validated on the correct language of Kyozo here,
and then what I do is if Kyozo line is equal to zero.
The cursor is now equal to one, and then it's just so the line is equal to zero, so that's pretty
common for you.
Now you just alternate between zero and one to the next time you enter this, the line will be different.
All right.
So to recap, we validate the text.
We said the cursor to the right place.
We printed the text and we alternate because of the next time.
And that's pretty much it.
So let's see if the code compiles and let's say it as activity.
16.
All right, no, let's applaud the cut to the original.
OK, I'm going to open the sale monitor also so you can see on the arena board we have well, on the
LCD, we have nothing, OK, no text is printed because we didn't ask to print anything.
I'm going to send hello know like this on the sale, Marinko, and you can see Hello, Alino, on the
first line.
And then let's send another text which will be printed on the line number two.
OK, now let's say I send a very, very, very long text.
OK, this will be more than 16 characters.
You can see text too long, OK?
And this has been printed on the first line again.
OK, let's try with yet another text.
OK, this is perfectly 16 character and this is printed on the second line.
OK, no, let's just print ABC and well that's something that we are going to need to fix in your code
because you can see here we have ABC, which was printed on the line number zero here and the on number
zero.
So it will replace all the text, OK, all the text that is going to be printed.
We replace the previous text, but all the text that is after that will actually not be replaced.
So now you have problem, try to send some short strings and if you already have some text, you can
see, well, that's just going to replace the text and then you have a mess on your display screen.
So let's fix that.
And actually, that's pretty easy.
After we have validated text, what do we can do is to add some space to complete the 16 characters
for the line.
OK, so you have two choices.
If you want to clear spaces on the LCD screen, you can use LCD clear.
But if you do, that is going to clear all the LCD.
So you are going to lose the two lines.
OK.
The other option is simply to print some and text or just on space.
So you are going to remove the previous characters.
So what I'm going to do here, I'm going to the four and then I'm going to do a follow up to add characters
to finish the line and I'm going to start.
So I is equal to text.
So if the text length is, let's say, four characters, I'm going to start at four.
OK, and then it is strictly lower than 16.
So I'm going to go so let's say from four to 15, OK, which is just before 16, a plus plus.
And what do I do here?
I'm going to do text and in plus equal to add the character and I'm going to add just an empty character.
So just a space.
So let's say your text is.
ABC, OK, this is three characters, what these followed will do is simply add characters here to make
it up to.
So I don't know exactly, but here let's say this is 16 characters.
So this is the text that you are going to print.
OK, so if previously you had some other text here in the OK, let's let's say you have this.
And if you're replaced with this, all of the text here will be replaced by empty spaces and you are
going to clear the rest of the screen.
So, no, let's upload this.
And now let's open the say on.
I'm going to send a long stream, quite long string and see yet another text.
OK, and now I'm going to send just text, which should replace the first line.
And you can see we have the correct behavior, ABC.
OK, if I send a very long screen, takes too long.
OK, and then let's send a load.
And we know, OK, and then I just sent A I just think B and you can see we have the correct behavior.
All right.
And this is the end of this activity.