WEBVTT

00:00.240 --> 00:06.840
This is the solution of the previous activity where you need to get a string from the cell communication,

00:07.050 --> 00:11.710
so you read the string and you print it on the LCD display screen.

00:12.240 --> 00:15.810
So let's start with the cellular communication.

00:16.140 --> 00:17.620
I'm going to initialized to you.

00:18.030 --> 00:33.020
Say all that, begin OK, and then sell it time out with 10 milliseconds in the loop function.

00:33.030 --> 00:40.030
I'm going to do if sale if the label is greater than zero.

00:40.530 --> 00:45.450
So if we have received any data, we are going to put this into a string.

00:46.080 --> 00:51.870
Text is equal to say you read string.

00:53.920 --> 00:58.250
And we got the text, so that's pretty much it for the cell communication.

00:58.270 --> 01:00.220
You don't need to do anything else.

01:00.220 --> 01:03.960
You just take cell available and then read train.

01:04.450 --> 01:14.890
Now, what I'm going to do is I'm going to create a function here, void print, use a text on display

01:16.010 --> 01:19.320
with a string text as a parameter.

01:20.740 --> 01:24.520
And here we are going to print the text on Etsy.

01:25.270 --> 01:32.050
So then I can use this function here directly after I have read the string, I'm going to send it to

01:32.050 --> 01:38.340
that function so I don't need to write the code of that function in the loop and know where our value

01:38.350 --> 01:40.300
is complete for this activity.

01:40.690 --> 01:47.340
OK, so we keep it minimal and then we have the functionality here in the function that.

01:47.800 --> 01:49.970
All right, that's it for the sale.

01:49.990 --> 01:55.420
No, let's initialize the liquid crystal display on the LCD screen.

01:56.050 --> 01:57.490
So include.

01:59.520 --> 02:06.060
Liquid crystal dumped H and then we need to do a bunch of defiance.

02:06.510 --> 02:10.200
I'm going to do them here once again for this activity.

02:10.650 --> 02:12.720
So Elsley up as.

02:13.750 --> 02:16.810
Dean, which is a fine for me.

02:18.280 --> 02:31.030
And C, d, e, d, which is a four, then define LCG before being which is number six and need to do

02:31.030 --> 02:41.440
this three more times or so, the five, which has been number seven, the six which is PIN number eight

02:41.440 --> 02:51.820
and seven, which is number nine, I got my six being set to correctly make sure you don't make any

02:51.820 --> 02:55.060
mistakes and then I'm going to create so leaky.

02:57.060 --> 03:04.830
Crystal LCD, I create these in global scope so that I can access the LCD screen everywhere in my program,

03:05.670 --> 03:07.350
we first address.

03:08.860 --> 03:12.790
Then in, then defore.

03:14.120 --> 03:19.790
All right, I go to a new line to make it better and more readable, the five.

03:22.060 --> 03:23.770
The six.

03:25.330 --> 03:28.030
And D7 and that's it.

03:28.900 --> 03:39.670
OK, our LCD is now here, and what I can do in the setup is the LCD begin 16 by two because this is

03:40.300 --> 03:41.590
the hardware that we have.

03:42.280 --> 03:42.610
Great.

03:42.620 --> 03:44.920
So now everything is set up.

03:45.730 --> 03:48.170
We receive the text from the sale.

03:48.190 --> 03:54.860
Now we can use this function to print the text on SD and actually what are we going to do in that function?

03:55.240 --> 03:58.360
So first we are going to validate the text.

03:58.510 --> 04:00.800
OK, validate that it's not too long.

04:01.060 --> 04:13.750
OK, after we do this, we set the cursor with a line zero one and then print text and let's start by

04:13.750 --> 04:16.520
validating the text length.

04:16.540 --> 04:25.240
So if text that length you have the length function, OK, which give you the length of the text.

04:25.240 --> 04:27.420
Quite straightforward here.

04:28.690 --> 04:31.090
This is greater than 16.

04:32.100 --> 04:32.910
And what do we do?

04:32.970 --> 04:39.150
I'm simply going to do this text is equal to text to log.

04:40.300 --> 04:46.810
So if the text is too long, I just replaced the text with another text and this is the error message

04:46.810 --> 04:48.220
that we are going to print.

04:48.690 --> 04:49.990
OK, that is good.

04:50.020 --> 04:59.030
Now, we said the cursor to line zero one, so let's do LCD notes, said Jesso.

04:59.740 --> 05:01.540
So the column will be zero.

05:01.540 --> 05:05.100
And then the line how to alternate between the lines with.

05:05.140 --> 05:05.930
It's quite simple.

05:05.950 --> 05:10.720
We are going to create a new viable here line.

05:10.720 --> 05:14.910
Let's initialize it to zero and going to put it there.

05:15.610 --> 05:19.600
So first time it's zero and then we are going to toggle this.

05:19.600 --> 05:21.400
If it's zero, we set one.

05:21.400 --> 05:23.320
If it's one we said to zero.

05:23.570 --> 05:30.970
OK, so right now here I'm setting the closer to column zero and the cursor line, which is either zero

05:30.970 --> 05:31.510
or one.

05:31.750 --> 05:34.060
And then I can do that print.

05:35.400 --> 05:40.410
Let's do that, actually, let's put that here and see what Prince.

05:41.590 --> 05:49.740
Text, so we are printing the text that is already validated on the correct language of Kyozo here,

05:50.110 --> 05:54.820
and then what I do is if Kyozo line is equal to zero.

05:56.340 --> 06:05.460
The cursor is now equal to one, and then it's just so the line is equal to zero, so that's pretty

06:05.460 --> 06:06.250
common for you.

06:06.300 --> 06:13.110
Now you just alternate between zero and one to the next time you enter this, the line will be different.

06:13.530 --> 06:13.860
All right.

06:13.870 --> 06:16.020
So to recap, we validate the text.

06:16.290 --> 06:18.300
We said the cursor to the right place.

06:18.300 --> 06:22.350
We printed the text and we alternate because of the next time.

06:22.720 --> 06:23.780
And that's pretty much it.

06:24.030 --> 06:28.740
So let's see if the code compiles and let's say it as activity.

06:30.160 --> 06:30.940
16.

06:33.310 --> 06:36.790
All right, no, let's applaud the cut to the original.

06:38.630 --> 06:47.180
OK, I'm going to open the sale monitor also so you can see on the arena board we have well, on the

06:47.180 --> 06:52.790
LCD, we have nothing, OK, no text is printed because we didn't ask to print anything.

06:52.950 --> 06:59.510
I'm going to send hello know like this on the sale, Marinko, and you can see Hello, Alino, on the

06:59.510 --> 07:00.620
first line.

07:00.980 --> 07:08.760
And then let's send another text which will be printed on the line number two.

07:08.960 --> 07:16.070
OK, now let's say I send a very, very, very long text.

07:16.340 --> 07:19.040
OK, this will be more than 16 characters.

07:19.490 --> 07:22.570
You can see text too long, OK?

07:23.090 --> 07:26.630
And this has been printed on the first line again.

07:26.660 --> 07:31.790
OK, let's try with yet another text.

07:32.750 --> 07:37.940
OK, this is perfectly 16 character and this is printed on the second line.

07:38.060 --> 07:46.240
OK, no, let's just print ABC and well that's something that we are going to need to fix in your code

07:46.250 --> 07:55.040
because you can see here we have ABC, which was printed on the line number zero here and the on number

07:55.040 --> 07:55.400
zero.

07:55.850 --> 08:00.770
So it will replace all the text, OK, all the text that is going to be printed.

08:01.010 --> 08:07.200
We replace the previous text, but all the text that is after that will actually not be replaced.

08:07.490 --> 08:13.310
So now you have problem, try to send some short strings and if you already have some text, you can

08:13.310 --> 08:21.800
see, well, that's just going to replace the text and then you have a mess on your display screen.

08:21.800 --> 08:22.760
So let's fix that.

08:23.240 --> 08:25.400
And actually, that's pretty easy.

08:25.700 --> 08:33.680
After we have validated text, what do we can do is to add some space to complete the 16 characters

08:33.680 --> 08:34.290
for the line.

08:34.310 --> 08:36.140
OK, so you have two choices.

08:36.140 --> 08:41.810
If you want to clear spaces on the LCD screen, you can use LCD clear.

08:41.960 --> 08:45.080
But if you do, that is going to clear all the LCD.

08:45.170 --> 08:47.220
So you are going to lose the two lines.

08:47.330 --> 08:47.640
OK.

08:48.110 --> 08:53.180
The other option is simply to print some and text or just on space.

08:53.510 --> 08:55.850
So you are going to remove the previous characters.

08:56.450 --> 09:02.480
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

09:02.480 --> 09:05.580
to finish the line and I'm going to start.

09:05.610 --> 09:08.300
So I is equal to text.

09:13.650 --> 09:20.100
So if the text length is, let's say, four characters, I'm going to start at four.

09:20.440 --> 09:24.410
OK, and then it is strictly lower than 16.

09:24.930 --> 09:32.620
So I'm going to go so let's say from four to 15, OK, which is just before 16, a plus plus.

09:33.060 --> 09:34.600
And what do I do here?

09:34.980 --> 09:42.660
I'm going to do text and in plus equal to add the character and I'm going to add just an empty character.

09:42.690 --> 09:43.700
So just a space.

09:44.370 --> 09:46.500
So let's say your text is.

09:48.200 --> 09:56.960
ABC, OK, this is three characters, what these followed will do is simply add characters here to make

09:56.960 --> 09:57.860
it up to.

09:58.190 --> 10:01.870
So I don't know exactly, but here let's say this is 16 characters.

10:02.120 --> 10:04.550
So this is the text that you are going to print.

10:04.580 --> 10:14.540
OK, so if previously you had some other text here in the OK, let's let's say you have this.

10:15.970 --> 10:25.060
And if you're replaced with this, all of the text here will be replaced by empty spaces and you are

10:25.060 --> 10:27.140
going to clear the rest of the screen.

10:27.730 --> 10:29.530
So, no, let's upload this.

10:31.110 --> 10:32.580
And now let's open the say on.

10:33.180 --> 10:41.250
I'm going to send a long stream, quite long string and see yet another text.

10:41.490 --> 10:46.530
OK, and now I'm going to send just text, which should replace the first line.

10:46.800 --> 10:50.180
And you can see we have the correct behavior, ABC.

10:50.580 --> 10:55.600
OK, if I send a very long screen, takes too long.

10:55.620 --> 10:59.670
OK, and then let's send a load.

11:01.680 --> 11:08.900
And we know, OK, and then I just sent A I just think B and you can see we have the correct behavior.

11:09.600 --> 11:10.100
All right.

11:10.110 --> 11:12.290
And this is the end of this activity.
