1 00:00:00,370 --> 00:00:08,130 Hello, today we are going to program a new circuit. It's similar to the ones we have 2 00:00:08,130 --> 00:00:15,890 already programmed. We will use the protoboard, the Arduino board, and we are going to use 3 00:00:15,890 --> 00:00:23,969 three LEDs. So we click and drag, click and drag, and click and drag. 4 00:00:24,609 --> 00:00:29,890 And we are going to connect them in a similar way we have connected them before. 5 00:00:30,050 --> 00:00:43,049 We use a black wire here, because it's connected to the ground, this is the ground, and we are going to use the three protection resistors. 6 00:00:43,049 --> 00:00:54,049 Remember that the protection resistor, the three of them, every protection resistor is going to be 220 ohms, not kilo ohms, ohms. 7 00:00:54,049 --> 00:01:04,430 and again with another protection resistor again 220 ohms and again with 8 00:01:04,430 --> 00:01:13,890 the third one here 220 ohms okay and this LEDs the three of them are going to 9 00:01:13,890 --> 00:01:27,530 connected to 13, 12 and 11. Ok, so these three LEDs are going to be our output and 10 00:01:27,530 --> 00:01:33,269 now the different part because we are going to use these switches. We are going 11 00:01:33,269 --> 00:01:41,150 to use two switches because we are going to use two digital inputs. We are going 12 00:01:41,150 --> 00:01:53,530 to use 10. I'm going to use an orange wire. Why orange? Just because. And the same orange 13 00:01:53,530 --> 00:02:03,150 here. And remember that we are going to connect, we need a pull-down resistor. You remember 14 00:02:03,150 --> 00:02:09,389 when we have, when we used the single button, it was 10 kilo ohms. The pull-down resistor 15 00:02:09,389 --> 00:02:18,810 was a 10 kilo ohms one. And again, a 10 kilo ohms one here. And here, I'm sorry, this one 16 00:02:18,810 --> 00:02:24,830 is going to be here, and this one is going to be here. And 10 kilo ohms, both of them. 17 00:02:27,259 --> 00:02:36,659 Okay. And we also need a 5 volts connector. We take it here, 5 volts, and I'm going to 18 00:02:36,659 --> 00:02:40,659 connected here, and this one is going to be red. And I need 19 00:02:40,659 --> 00:02:44,460 a red connection here. I mean red because it's not 20 00:02:44,460 --> 00:02:48,479 black, right? Because I want five volts here 21 00:02:48,479 --> 00:02:52,639 and the same with this one. I made 22 00:02:52,639 --> 00:02:56,639 a mistake. This one has to be connected here. Can you see the difference? And the same with 23 00:02:56,639 --> 00:03:00,840 this one. Right. Sometimes we make mistakes 24 00:03:00,840 --> 00:03:04,900 connecting wires, and that's why sometimes the circuits 25 00:03:04,900 --> 00:03:12,280 don't work this is not nothing related to the programming is related is because we have we 26 00:03:12,280 --> 00:03:19,159 haven't connected the wires properly so here instead of having the usual button i have two 27 00:03:19,159 --> 00:03:24,979 switches why two switches because i'm going to manipulate them this way when i press one of them 28 00:03:24,979 --> 00:03:31,439 i have a single pointer pointer if i want to press the other one i cannot be pressing by both 29 00:03:31,439 --> 00:03:37,780 positions at the same time. So, that's why I'm going to use a switch. A switch has, remember, 30 00:03:37,780 --> 00:03:44,500 we studied the switch in the classroom. The switch, I mean, switches have two permanent 31 00:03:44,500 --> 00:03:49,620 states on and off. That's why we need two switches instead of two buttons because if 32 00:03:49,620 --> 00:03:57,759 we use a button, the moment we finish pressing, the connection is closed, okay? So, that's 33 00:03:57,759 --> 00:04:01,000 That's why we are using two switches. 34 00:04:01,000 --> 00:04:06,159 You will understand it better later in the simulation. 35 00:04:06,159 --> 00:04:11,419 So this switch is connected the same way the button has been connected. 36 00:04:11,419 --> 00:04:16,720 Now there is no connection between this point and this point, okay, can you see this position? 37 00:04:16,720 --> 00:04:22,300 So here this wire is connected to ground through the pull-down resistor. 38 00:04:22,300 --> 00:04:26,000 The moment there is a connection between this wire and this wire, I have five volts here 39 00:04:26,000 --> 00:04:31,000 and five volts will be red here in the connector 10, 40 00:04:31,259 --> 00:04:32,879 and the same for number nine, okay? 41 00:04:34,000 --> 00:04:35,480 Now, the simulation. 42 00:04:36,500 --> 00:04:37,639 What do I want to do? 43 00:04:38,180 --> 00:04:40,699 I want to simulate the circuit this way. 44 00:04:41,540 --> 00:04:42,939 I'm going to, first of all, 45 00:04:42,959 --> 00:04:44,759 I'm going to program it step by step. 46 00:04:44,759 --> 00:04:48,399 The first thing I need are two variables. 47 00:04:49,139 --> 00:04:54,579 I'm going to name them input nine and input 10. 48 00:04:54,579 --> 00:04:59,120 Why? Because we are reading two inputs, from 9 and from 10. 49 00:04:59,439 --> 00:05:01,420 The second variable will be input 10. 50 00:05:03,879 --> 00:05:10,089 For the moment, I haven't said anything about the behavior of the circuit. 51 00:05:10,790 --> 00:05:12,829 I'm going to explain it while I'm programming it. 52 00:05:12,930 --> 00:05:15,189 Don't worry if you don't understand because I haven't said anything. 53 00:05:15,930 --> 00:05:22,009 So, the first thing we are going to do is reading number 9 and number 10. 54 00:05:22,009 --> 00:05:25,529 We have Entraje, Ler, Pasador, Digital. 55 00:05:26,050 --> 00:05:31,889 So we are going to read 9 and we are going to read 10 56 00:05:31,889 --> 00:05:35,209 because they are the ones we are reading, 9 and 10. 57 00:05:35,629 --> 00:05:42,269 And we are going to use these readings to define input 9 58 00:05:42,269 --> 00:05:46,490 and to define input 10. 59 00:05:46,490 --> 00:05:56,490 It means we are reading these two connectors and we are storing their values into variables. 60 00:05:56,490 --> 00:06:03,490 Remember that the variables are like boxes and we can store values inside them. 61 00:06:03,490 --> 00:06:10,490 Here we are going to store high or low depending if the switch is on or off. 62 00:06:10,490 --> 00:06:14,490 So, now, the behavior. What do I want? 63 00:06:14,490 --> 00:06:17,329 Well, first of all, I need an if. 64 00:06:17,889 --> 00:06:18,790 Remember the si? 65 00:06:19,829 --> 00:06:22,879 There are four possibilities. 66 00:06:23,600 --> 00:06:25,600 The two switches on, the two switches off, 67 00:06:26,079 --> 00:06:28,019 the first one off and the second one on, 68 00:06:28,459 --> 00:06:31,660 and the first one off and the second one on, or vice versa. 69 00:06:31,660 --> 00:06:35,819 Anyway, I want, I need two ifs. 70 00:06:35,819 --> 00:06:36,899 Si, si entonces. 71 00:06:37,540 --> 00:06:39,480 And there are four possibilities. 72 00:06:40,980 --> 00:06:43,500 And to compare, remember that we already know 73 00:06:43,500 --> 00:06:48,019 this one equals 74 00:06:48,019 --> 00:06:53,769 in the previous exercises we have used this one equal 75 00:06:53,769 --> 00:06:58,370 and equal. I need two of them because here I'm going to use 76 00:06:58,370 --> 00:07:02,230 the and connector. I'm going to make it smaller to make it a little bit easier 77 00:07:02,230 --> 00:07:07,970 because there are two possibilities. First possibility 78 00:07:07,970 --> 00:07:14,579 number nine, low. Let's have a look here 79 00:07:14,579 --> 00:07:22,550 no, low and another possibility is 80 00:07:22,550 --> 00:07:37,569 number 10 low. And if 9 is low and 10 is low, to combine both of them, I'm going to use the 81 00:07:37,569 --> 00:07:47,569 i, the ant in English. Can you see that I'm combining them? So here the condition is if 9 is low 82 00:07:47,569 --> 00:07:56,569 and 9 is low, something will happen. I click and drag. So I'm using this condition. Instead of 83 00:07:56,569 --> 00:08:01,810 Instead of using one single condition, we are combining two conditions using the AND, okay? 84 00:08:01,970 --> 00:08:06,209 This is the purpose of this exercise, combining two different conditions. 85 00:08:06,509 --> 00:08:09,009 That's why we have two different inputs. 86 00:08:09,670 --> 00:08:11,829 What do I want if both of them are off? 87 00:08:12,110 --> 00:08:12,689 I don't know. 88 00:08:12,910 --> 00:08:13,750 Whatever you want. 89 00:08:14,370 --> 00:08:21,089 So we are considering that if both of them are low, 13, 12, 11 are low. 90 00:08:22,089 --> 00:08:22,689 It's really easy. 91 00:08:22,689 --> 00:08:48,980 We use three blocks, like, oh, I'm sorry, I made a mistake, be careful when you are moving and dragging the blocks, so if 9 and 10 are low, I will decide that 13, 12, and 11, the three of them are low. 92 00:08:48,980 --> 00:08:52,320 Why? Just because. Just because I want. 93 00:08:53,299 --> 00:08:57,000 Okay. What else? Anyway, I'm going to remove 94 00:08:57,000 --> 00:09:00,559 these three ones and I'm going to copy because it's easier this way. Duplicate. 95 00:09:01,600 --> 00:09:04,820 What happens if 9 is high 96 00:09:04,820 --> 00:09:11,009 and 10 is low? I don't know. What do we 97 00:09:11,009 --> 00:09:15,009 want? For instance, we want that 13 is high. Why not? 98 00:09:15,730 --> 00:09:18,710 13. If we press this one, this one will be high. 99 00:09:18,710 --> 00:09:35,190 Why not? Okay, this is the second possibility. What happens if 9 is low and 10 is high? 100 00:09:39,740 --> 00:09:48,840 So it means that if we are pressing this one or if this one is on, for example, I want this one is 101 00:09:48,840 --> 00:10:03,049 is high. Why not? So this one is 11, 11 high. Okay. Why? Just because I am programming it 102 00:10:03,049 --> 00:10:16,570 this way. And what happens if the two of them, 9 and 10, are high? Okay. Just because we 103 00:10:16,570 --> 00:10:28,169 want, we can program a blinking. So we are going to program a blink the way we know it. 104 00:10:28,169 --> 00:10:41,950 Now we use await, and now I'm going to duplicate this part of the code. Baja, low, low, and 105 00:10:41,950 --> 00:10:49,710 low. Do you agree that if both of them are low, sorry, low and low, if both of them are 106 00:10:49,710 --> 00:10:57,129 low, if 9 and 10 are low, this is a blinking program. Okay. So realize that there are four 107 00:10:57,129 --> 00:11:02,610 if blocks, four if parts, because we have the four possibilities. Low and low, low and 108 00:11:02,610 --> 00:11:09,190 high, high and low, and high and high. And for every possibility, I have a different 109 00:11:09,190 --> 00:11:18,149 behavior. Okay. Let's see if it works the way we have programmed it. Okay. Okay. Both of them are 110 00:11:18,149 --> 00:11:27,320 off. The three lights are off, as expected. If this one is... I made a mistake. I don't know. 111 00:11:28,639 --> 00:11:34,039 Ah, where's the mistake? Again, a problem with the wires. There is no ground connection. 112 00:11:34,039 --> 00:11:50,029 be careful with the grounds black can you see that now that the three resistors are connected 113 00:11:50,029 --> 00:11:56,269 to ground now i'm i am closing the circuit now everything will work let's start again 114 00:11:56,269 --> 00:12:12,139 okay okay okay again there is a problem with the connections 115 00:12:12,139 --> 00:12:23,120 Where's the problem? Ah no, there's no problem 116 00:12:23,120 --> 00:12:27,820 because it's according to the program. If the three of them 117 00:12:27,820 --> 00:12:30,940 are low, if the two of them are low, there is a blink 118 00:12:30,940 --> 00:12:39,110 It makes sense. If, oh I'm sorry, if the two 119 00:12:39,110 --> 00:12:46,350 of them are high, this is, no 120 00:12:46,350 --> 00:12:49,409 I made a mistake. I made a mistake with the program 121 00:12:49,409 --> 00:12:58,049 I want to check it again. Alta, baja, baja. And it's the last part of this alta, alta, okay? 122 00:13:00,230 --> 00:13:12,820 Alta, alta. If both of them are high, we want a blink. If both of them are low, alta, alta, baja, baja, alta, alta, baja, baja. 123 00:13:13,379 --> 00:13:16,240 They are low, alta, alta, it's a blink, okay? 124 00:13:16,240 --> 00:13:22,809 It's important that when you program, you check the behavior with your programming. 125 00:13:22,809 --> 00:13:27,809 It's not a big problem making mistakes. Now, the two of them are low. 126 00:13:27,809 --> 00:13:32,809 Baja, baja. Nothing happens. They are low. If I press this one, 127 00:13:32,809 --> 00:13:42,679 this one is 10. Alta. 128 00:13:42,679 --> 00:13:47,679 Two of them are high. I'm going to modify it just because I want to. I want to 129 00:13:47,679 --> 00:13:56,159 to consider that just 11 is low, is high and mean. Can you see the difference now? Okay, 130 00:13:56,159 --> 00:14:03,279 let's start the simulation again. Both of them are off, nothing happens. If I press 131 00:14:03,279 --> 00:14:10,299 this one, this one is shining, perfect, according to the program. If just this one is on, this 132 00:14:10,299 --> 00:14:14,519 one is shining, perfect, according to the program. And what happens if the two of them 133 00:14:14,519 --> 00:14:22,440 are high, the blinking program. So the program works, the circuit behaves according to the 134 00:14:22,440 --> 00:14:27,320 programming. We have made some mistakes, but this is not a big problem, it's not a big issue, 135 00:14:27,320 --> 00:14:32,840 because we can check, we can compare, we program with the behavior, the same way that when you 136 00:14:32,840 --> 00:14:39,240 simulate the circuit, you can check the behavior with your program, with the way you have connected 137 00:14:39,240 --> 00:14:45,879 or the way you have connected everything, okay? So this is the circuit, okay? I repeat the behavior. 138 00:14:45,879 --> 00:14:51,159 If nothing is connected, nothing happens. If one of them is connected, this one is shining. 139 00:14:51,879 --> 00:14:56,919 If the other one is connected, this other one is shining. And if both of them are connected, 140 00:14:57,559 --> 00:15:03,480 there is a blink. The three of them, the three LEDs are blinking, okay? So the important thing 141 00:15:03,480 --> 00:15:10,519 is realizing that there are four possibilities baja baja low low high low low high and high high 142 00:15:10,519 --> 00:15:17,879 okay check the four possibilities don't make the same mistake i made and compare with the 143 00:15:19,000 --> 00:15:23,320 compare the four possibilities the four behaviors okay 144 00:15:23,320 --> 00:15:28,840 it's not it's not difficult okay so this is the exercise for today good luck