1 00:00:00,050 --> 00:00:06,110 Hello. In this exercise, we are going to continue studying how the computer can communicate, 2 00:00:06,469 --> 00:00:08,789 can send and receive information from the Arduino board. 3 00:00:09,849 --> 00:00:13,650 Here on the screen, you can see the circuit we are going to use. 4 00:00:13,890 --> 00:00:20,629 We have four LEDs connected to the usual connectors, 13, 12, 11 and 10. 5 00:00:21,250 --> 00:00:27,949 We are going to use digital outputs and every LED is connected to a 220 ohms protection resistor. 6 00:00:27,949 --> 00:00:35,789 okay so nothing new for the moment let's go to the code we're going to have a look at the code here 7 00:00:36,590 --> 00:00:43,950 this block layer de la serie read from the serial monitor is the the new one this is a 8 00:00:43,950 --> 00:00:49,710 purple block it means that this from the input library and it means that the Arduino board is 9 00:00:49,710 --> 00:00:54,750 reading from the serial connection it means it's reading from the wire that is connected to the 10 00:00:54,750 --> 00:00:58,189 from the USB that is connected to the computer. 11 00:00:58,189 --> 00:01:01,869 So we have a variable that is called serie, just because I want 12 00:01:01,869 --> 00:01:07,310 this name. So we take the value, the number, from the USB, from the wire, 13 00:01:07,310 --> 00:01:11,390 and we store it inside the variable. 14 00:01:11,390 --> 00:01:17,310 And now I'm going to use this variable to control the Arduino board. Here, for 15 00:01:17,310 --> 00:01:22,750 instance, just because I want, if this variable equals 1, 13 will be 16 00:01:22,750 --> 00:01:29,629 high so it means the red led will shine so let's have a look let's start the simulation 17 00:01:30,349 --> 00:01:36,670 i start nothing happens remember that the serial monitor is here if i click here and to send 18 00:01:36,670 --> 00:01:44,430 variables we send number we have to type here in this box if i type one and i press enter 19 00:01:44,430 --> 00:01:52,670 nothing happens. Yes, because there is a problem. This block, LeerSerie, is not 20 00:01:52,670 --> 00:01:57,310 a good one if we want to read integer numbers. There is a problem with the 21 00:01:57,310 --> 00:02:00,989 simulation, but it's not a huge problem, it's not a big problem, we can solve it 22 00:02:00,989 --> 00:02:06,870 this way. We are going to change from Blocks to Text. Remember 23 00:02:06,870 --> 00:02:11,550 when we... well, don't remember, it's the first time we do this. When we change 24 00:02:11,550 --> 00:02:18,389 from blocks to code we will not be able to come back to the blocks okay so when 25 00:02:18,389 --> 00:02:26,289 we change we have to be sure about the things we are doing okay so we click 26 00:02:26,289 --> 00:02:33,030 here continue and we have here the code so here this is the variable I mean the 27 00:02:33,030 --> 00:02:38,330 function we are using to read serie the variable equals this function so here 28 00:02:38,330 --> 00:02:43,949 instead of using SerialRead, we are going to use a new function that is 29 00:02:43,949 --> 00:02:52,669 called SerialParseInt. If you have any problem writing here, try a 30 00:02:52,669 --> 00:02:58,250 second time or a third time, okay? It works, but sometimes you can't do it the 31 00:02:58,250 --> 00:03:02,610 first time, I don't know why. So here we have the new code. I have only 32 00:03:02,610 --> 00:03:07,849 changed this function we are using to read the number, and now I'm going to 33 00:03:07,849 --> 00:03:16,550 start the simulation again. And now, if I press 1 here, the LED is 34 00:03:16,550 --> 00:03:22,469 shining, okay? This is really really simple. So, your exercise. Your exercise is 35 00:03:22,469 --> 00:03:30,650 a little bit more complicated than this one. You will repeat the code, you will go 36 00:03:30,650 --> 00:03:35,610 back, you will remember that you can stop the video and go back, and you 37 00:03:35,610 --> 00:03:43,050 You will read the variable the same way and you will add several blocks for switching 38 00:03:43,050 --> 00:03:46,389 it on, switching it on, switching it on, switching it on. 39 00:03:46,389 --> 00:03:51,830 You will have four numbers to switch each one of them on and you will use other four 40 00:03:51,830 --> 00:03:53,650 numbers to switch them off. 41 00:03:53,650 --> 00:03:58,030 And remember, the serial monitor here for you is here, okay? 42 00:03:58,030 --> 00:04:03,150 So for example, you can use one, two, three and four to switch them, one, two, three and 43 00:04:03,150 --> 00:04:07,750 four the four of them or maybe you can or and then you can use for instance five six seven and eight 44 00:04:07,750 --> 00:04:16,050 to make them off the orders you are sending to the i mean through the usb okay i think it's not 45 00:04:16,050 --> 00:04:21,209 really easy if you can you can program it instead of repeating the blocks you can copy and paste 46 00:04:21,209 --> 00:04:28,389 this part okay this is the part we you can copy and paste to reproduce the different orders the 47 00:04:28,389 --> 00:04:34,089 different possibilities 13 is the number of the connector instead of high you can use low and 48 00:04:34,089 --> 00:04:39,189 one is here is the number of the code we use to send information so you can copy and paste this 49 00:04:39,189 --> 00:04:43,790 part of the code if you want to okay you don't have to go back to the blocks program a new a 50 00:04:43,790 --> 00:04:48,870 new circuit and then create a new a new code you don't have to you can copy and paste this part 51 00:04:48,870 --> 00:04:55,790 however many times you want okay so the exercise is really simple but before i leave i want to 52 00:04:55,790 --> 00:05:04,910 show you this exercise in the real life here i have copied and pasted my code and i go to i'm 53 00:05:04,910 --> 00:05:10,129 going to upload it to the computer and check that everything is correct verificar okay compilado 54 00:05:10,129 --> 00:05:17,290 fine everything works i upload it to the arduino board okay subiendo subido upload it and now i go 55 00:05:17,290 --> 00:05:25,029 to the serial monitor here so i'm going to send my commands the first one is 13 why 13 just because 56 00:05:25,029 --> 00:05:34,149 I want to and I want to type 13 the first LED is shining what happens if I type 12 why 12 just 57 00:05:34,149 --> 00:05:42,329 because the green one is shining what happens if I type 11 the yellow one is shining again why 11 58 00:05:42,329 --> 00:05:55,569 just because I want to what happens if I type 113 the red one is off 112 the green one is off 59 00:05:55,569 --> 00:06:05,420 and 111 the yellow one is off so the real interesting thing here is that i can control 60 00:06:05,420 --> 00:06:11,399 the arduino board from my keyboard okay for me this is the the amazing thing so and you can see 61 00:06:11,399 --> 00:06:16,860 that it's true in real life it works okay so okay remember distractions you have to do something 62 00:06:16,860 --> 00:06:23,680 like this programming orders orders to switch all the leds on and to switch all of them off 63 00:06:23,680 --> 00:06:28,579 If you have understood the exercise with one LED switching it on, it's enough. 64 00:06:28,660 --> 00:06:32,339 You don't need nothing more to understand and to do the exercise, okay? 65 00:06:32,800 --> 00:06:34,259 So, good luck.