In this new activity, you are going to control your Arduino from Telegram and of course, going through
the Raspberry Pi.
So basically what you have to do is so when you're going to send some comments from the chat, so you're
going to control the RGB led and the LCD screen.
So for example, you type slash LCD, that's going to be the command and then some text, okay, you're
going to type this.
So for now it doesn't do anything.
And this text here should appear on the LCD screen and also a command for the RGB led.
Okay.
So now we arrive at things a little bit more complex.
But again, if you have correctly understood the following, it should not be a problem.
You can manage to do it by yourself.
So on the Arduino side, what you're going to do is just open and handle comments for RGB Led and LCD
screen.
So for the LCD screen, I will let you define a protocol.
So what kind of comment you can send from what we have done before, you should be able to do that.
And for the RGB led, what we have done previously was to set each color independently.
Okay, you would send red, you would send green and you would send blue.
Here we are going to improve a little bit and instead of sending green, blue, red, we are going to
just send one comment for the three colors.
Okay.
And here I have shown you an example.
Okay.
Actually, let's use comma.
So we have the command set led like this and then we have three numbers.
So this is going to be sent as a string, of course.
And so you check that the command starts with set Led, you remove the first one, two, three, four,
five, six, seven, eight characters and then you are left with this.
And then you have the substring function that you can use on the string on the Arduino string.
Okay.
To just get one part of the string.
So that's zero one, two, three.
Okay.
And then four, five, six, seven and then eight to the end and you're going to cast that to an integer.
And so you have red, green and blue.
One very important thing is that when you send the command from the Raspberry Pi and also from Telegram,
you have to respect the number of characters here.
Okay, So I have shown you an example.
So if you send 200 for red, you just put 200.
If you want to put zero for green, you don't just put zero like this, you have to put three zero for
it to work.
And for 80 you just don't send 80.
You send with a zero.
So you make sure you have three characters for each color.
Okay?
And that's the way we are going to be able to read the colors.
You could do something different, of course, to improve it, but we're going to stay with that.
And that's a pretty efficient way actually to set the Led.
Okay, so that's it for the Arduino side on the Raspberry Pi side.
So you're going to connect to Serial, you're going to create some.
So here you don't send notification to Telegram, you receive some comments.
So you're going to create a command handler with an update data, a dispatcher.
And then when you receive a command, you directly pass it to the Arduino, okay, with the correct
command.
So, for example, if I send here, let's say RGB and then so 200 comma, 000 comma zero 80, if I send
this and exactly this, you're going to receive that on the Raspberry Pi and you're not going to send
RGB, you're going to send set Led colon, you're going to add this and you're going to add a new line
character.
So you receive the command from Telegram on the Raspberry Pi and you make sure that you send the correct
command for the Arduino so that the Arduino can understand what you're asking to do.
Okay.
I will see you in the next lesson for the solution.