WEBVTT

00:00.050 --> 00:06.590
Let's quickly see how to control the RGB led with your Arduino once again in this section.

00:06.590 --> 00:08.360
I'm going to go quite fast.

00:08.390 --> 00:14.750
The goal is not to go into details about each Arduino functionality, but to reach the next activity

00:14.750 --> 00:21.650
part where you will practice on Arduino functionalities controlled by the Raspberry Pi using serial

00:21.650 --> 00:22.570
communication.

00:22.580 --> 00:27.260
So let's start and let's directly write some basic code for the RGB Led.

00:27.380 --> 00:30.860
So what you can do here already is to connect your Arduino.

00:30.860 --> 00:36.470
So once the circuit is correctly done, you can connect your Arduino back to the Raspberry Pi with the

00:36.470 --> 00:42.650
USB cable and then check that you have the Arduino connected here with the correct board, of course.

00:42.830 --> 00:48.230
And now, well, basically how to control an RGB led is very simple.

00:48.230 --> 00:52.310
If you already know and you probably already know how to control an Led.

00:52.490 --> 00:59.180
Well, an RGB Led is nothing more than three different LEDs when we speak about the code.

00:59.180 --> 01:04.350
So we are going to control each leg of each color separately.

01:04.350 --> 01:06.780
So I'm going to create some define here.

01:06.780 --> 01:12.810
So define RGB red pin with PIN number 11.

01:12.930 --> 01:16.320
So make sure that you use the pins you have selected.

01:16.320 --> 01:19.830
If you have selected different pins, define RGB.

01:21.030 --> 01:30.510
So green pin ten and define RGB blue pin nine.

01:30.510 --> 01:36.900
And if you have some doubt about the order of those pins for you, well, just start with this and then

01:36.900 --> 01:41.070
you will be able to change that after you experiment with some code.

01:41.070 --> 01:42.420
So we have the defines.

01:42.450 --> 01:48.810
Then what we do is we simply do pin mode on each leg.

01:48.810 --> 01:49.380
Okay?

01:49.470 --> 01:54.450
Just like we were controlling three different LEDs.

01:54.450 --> 01:56.970
Okay, so pin mode for the red pin.

01:57.390 --> 02:03.590
PIN mode for the green pin mode for the blue.

02:06.410 --> 02:07.040
Okay.

02:07.220 --> 02:09.740
Everything is correctly set up and then.

02:09.740 --> 02:11.480
Well, I'm not going to do anything in the loop.

02:11.480 --> 02:15.590
I'm just going to show you how to just power on this RGB led.

02:15.740 --> 02:21.080
So if you do digital right here, you can do digital, right?

02:21.080 --> 02:23.240
And you can also do analog, right?

02:23.240 --> 02:27.550
Because we are using pins that are compatible.

02:27.560 --> 02:28.850
I'm going to start with digital.

02:28.850 --> 02:29.480
Right?

02:29.780 --> 02:30.320
Okay.

02:30.830 --> 02:32.750
So you can put, for example.

02:32.990 --> 02:35.870
Hi, and then the digital.

02:35.900 --> 02:37.850
Let's just use the same here.

02:39.730 --> 02:45.370
So for the red and then for the green and then for the blue.

02:46.990 --> 02:51.340
So let's say we want only to power on so low.

02:51.610 --> 02:53.650
Only the green and the blue.

02:53.690 --> 02:53.910
Okay.

02:53.920 --> 02:56.830
To make a combination of green and blue color.

02:56.830 --> 03:05.160
So those are going to be powered on with full intensity and this one with zero intensity.

03:05.170 --> 03:09.400
So let's So board is connected.

03:09.430 --> 03:11.440
Let's upload.

03:14.140 --> 03:14.530
All right.

03:14.530 --> 03:21.220
And you can see we have this color, which is not exactly blue, not exactly green, but in the middle.

03:21.400 --> 03:24.280
So with this, you can do different combinations, okay?

03:24.310 --> 03:26.980
Up to seven different combinations.

03:26.980 --> 03:30.040
And then I'm going to comment this.

03:31.840 --> 03:34.960
And now let's see an example with analog.

03:36.080 --> 03:36.580
Right?

03:36.610 --> 03:37.210
Okay.

03:37.810 --> 03:41.620
So I'm going to use also the pin like this.

03:41.620 --> 03:45.550
And then you need to give a number between 0 and 255.

03:45.550 --> 03:48.430
So here you have more control over the colors.

03:48.460 --> 03:48.910
Okay?

03:48.910 --> 03:52.180
So if you put zero, that's going to be powered off.

03:52.180 --> 03:56.950
If you put 255, it's just like you use digital, right, with high.

03:56.980 --> 04:04.660
And then if you use any of, for example, the 180, this is going to be a percentage of the brightness

04:04.660 --> 04:07.210
basically between 0 and 255.

04:07.240 --> 04:11.860
That's going to be applied to the red color of the RGB.

04:12.250 --> 04:15.400
So let's do this.

04:15.400 --> 04:20.680
I'm going to use the same for the green, but I'm going to put zero here.

04:20.680 --> 04:23.290
I'm going to try to make a purple color.

04:23.320 --> 04:28.000
So I'm going to do blue and let's say 200.

04:28.030 --> 04:28.600
Okay.

04:28.690 --> 04:33.940
So we're going to do a mix of red and blue, which should turn purple.

04:34.180 --> 04:35.350
And let's see that.

04:35.350 --> 04:37.450
So let's run the code.

04:38.450 --> 04:41.900
Upload, uploading and done uploading.

04:42.080 --> 04:42.590
Okay.

04:42.590 --> 04:45.770
And we have a color that is purple.

04:46.730 --> 04:48.620
So that's pretty much it for the RGB.

04:49.250 --> 04:57.590
You first create some defined or const int and then you do pinmode for each pin and then you can use

04:57.590 --> 05:00.480
either digitalwrite or analogwrite.

05:00.530 --> 05:06.920
So this only if you have the functionality of course, and you can create any combination of color and

05:06.920 --> 05:09.020
this you can use in the setup in the loop.

05:09.020 --> 05:11.780
Well, you can use that anywhere you want.
