1 00:00:00,000 --> 00:00:08,199 Hello. In this exercise we are going to reuse a previous circuit. 2 00:00:09,060 --> 00:00:11,439 We are going to use the one with the digital input. 3 00:00:11,779 --> 00:00:19,260 So here, if we have all the circuits we already have, we can duplicate whatever we want. 4 00:00:19,559 --> 00:00:21,519 For instance, we are going to use the digital input. 5 00:00:22,019 --> 00:00:26,519 If we click on the wheel, we can duplicate it, we can copy it. 6 00:00:26,519 --> 00:00:33,439 We click on duplicate, wait a little bit, and a copy of this circuit will appear. 7 00:00:34,560 --> 00:00:38,020 In this exercise, we are going to use more or less the same connections. 8 00:00:38,340 --> 00:00:42,380 We are going to use the input, the digital input, with the button, the pull-down resistor, 9 00:00:42,740 --> 00:00:45,359 and we are going to use LEDs as output. 10 00:00:45,899 --> 00:00:49,500 But here, instead of having just one of them, we are going to use four of them. 11 00:00:50,100 --> 00:00:52,380 So, the first thing we need is a room. 12 00:00:52,500 --> 00:00:55,780 So, I'm going to click and drag the button here, for instance. 13 00:00:55,780 --> 00:01:01,340 I'm going to click and drag the wire, I'm going to click and drag the pull-down resistor, 14 00:01:01,340 --> 00:01:09,019 remember the 10 kOhms one, there you see, 10 kOhms one, and I'm going to click and drag 15 00:01:09,019 --> 00:01:12,099 the wire, the input wire. 16 00:01:12,099 --> 00:01:19,200 And I'm going to use number 13, 12, 11 and 10 to control 4 different LEDs, so I'm going 17 00:01:19,200 --> 00:01:25,420 to click and drag the input wire from the button to number 9. 18 00:01:25,420 --> 00:01:28,420 And now I'm going to click and drag the four LEDs. 19 00:01:28,420 --> 00:01:32,420 Well, I already have one, so just three of them. 20 00:01:32,420 --> 00:01:34,420 One, two, three, and four. 21 00:01:34,420 --> 00:01:38,420 And I will also need three more resistors. 22 00:01:38,420 --> 00:01:43,420 All of them connected to the anode, the one that is not straight. 23 00:01:43,420 --> 00:01:49,420 One, two, and three. 24 00:01:49,420 --> 00:01:52,420 And remember that I have to change their values. 25 00:01:52,420 --> 00:02:00,420 220 ohms 1, because this is the value we need to protect the LEDs. 26 00:02:00,420 --> 00:02:10,419 220 ohms. Ohms is not the same as kilo ohms, so that way I have changed the kilo ohms to 220 ohms. 27 00:02:10,419 --> 00:02:14,419 And now I'm going to connect the LEDs using the wires. 28 00:02:14,419 --> 00:02:20,419 The first connection I want is the four black wires that are connected to ground. 29 00:02:20,419 --> 00:02:33,180 black again, and black again. Here, black again. Okay. All of them... I made a mistake here. 30 00:02:33,180 --> 00:02:38,180 Be careful when you... I want to erase the whole thing. Be careful when you draw wires 31 00:02:38,180 --> 00:02:43,180 because sometimes you make mistake and you don't realize you have made a mistake. 32 00:02:43,180 --> 00:02:48,180 Now, I have a single wire. So, these four wires are connected to ground because this 33 00:02:48,180 --> 00:02:52,199 because this horizontal line can you see the horizontal line is connected to 34 00:02:52,199 --> 00:02:59,180 ground through this wire okay and now I want I need the connection from 12 to 35 00:02:59,180 --> 00:03:07,319 this one from 11 to this one and from 10 to this one so I have everything I need 36 00:03:07,319 --> 00:03:13,659 related to the different components now I need to program the circuit so I'm 37 00:03:13,659 --> 00:03:21,280 going to open the window related to code and I have the previous program. I want 38 00:03:21,280 --> 00:03:26,439 to modify it a little bit because some of the possibilities are, some of the ideas 39 00:03:26,439 --> 00:03:32,860 are the same. Again I am reading the input from number 9, so instead of 40 00:03:32,860 --> 00:03:39,280 reading from 12 now I'm reading from 9, so I will modify. Leer pasado digital, ok. 41 00:03:39,280 --> 00:03:43,039 I have a variable, I read from number 9 and I store it 42 00:03:43,039 --> 00:03:47,319 in this variable and if this variable 43 00:03:47,319 --> 00:03:51,060 if this input is high, something will happen here and if the 44 00:03:51,060 --> 00:03:55,180 input is not high, something else will happen here. So 45 00:03:55,180 --> 00:03:59,439 the first thing we need is, before we start moving on, is a 46 00:03:59,439 --> 00:04:03,460 random number. If we go to the 47 00:04:03,460 --> 00:04:07,280 green library, the one related to maths, there is a 48 00:04:09,280 --> 00:04:15,199 block here related to random number that allows us to generate random number here i want a random 49 00:04:15,199 --> 00:04:24,639 number from 10 to 13. why 10 to 13 because i'm going to use these four connectors so i'm going 50 00:04:24,639 --> 00:04:30,480 to select and i want to use a number from random number from 10 to 13. realize that there is a bar 51 00:04:30,480 --> 00:04:35,519 here if there's no enough room you can click and drag this bar and you will have enough room 52 00:04:35,519 --> 00:04:43,860 so the same way and we move on the same way we have done with this variable we are going to 53 00:04:43,860 --> 00:04:50,660 uh i know i'm sorry i i need an extra variable because i have a random number i was moving too 54 00:04:50,660 --> 00:04:56,180 fast i was a random number but i need to store it somewhere so i'm going to create a new variable 55 00:04:56,819 --> 00:05:04,180 this variable will i i can name it however i want but i'm going to use output because this random 56 00:05:04,180 --> 00:05:09,759 number will be the output that will shine so I'm going to work the same way 57 00:05:09,759 --> 00:05:17,860 I worked before I'm going to define I output using this random number okay so 58 00:05:17,860 --> 00:05:25,180 output will have this random number from 10 to 30 okay so what happens if I press 59 00:05:25,180 --> 00:05:30,240 the button one of the LEDs will shine which one it depends on the random 60 00:05:30,240 --> 00:05:37,000 number, so I have to check the value of the input, not the input, the output, I'm sorry. 61 00:05:37,000 --> 00:05:44,680 So I'm going to use the comparison block again, I'm going to use the equal, and I'm going 62 00:05:44,680 --> 00:05:47,740 to check the value of output. 63 00:05:47,740 --> 00:05:55,259 So for instance, if output equals 13, something will happen, but I need the if block to C, 64 00:05:55,259 --> 00:05:57,560 if C. 65 00:05:57,560 --> 00:06:04,399 Now I'm comparing. If this output, that is the random number, equals 13, what will happen? 66 00:06:04,399 --> 00:06:13,800 What do you think? It will happen that output number 13 will be high and this block will 67 00:06:13,800 --> 00:06:22,100 be here, inside the first if, because if the input, the one we are reading here, is high 68 00:06:22,100 --> 00:06:27,199 and the output, the random number, is 13, number 13 will shine. 69 00:06:28,279 --> 00:06:33,279 Something similar will happen with 12, 11, and 10. 70 00:06:33,600 --> 00:06:35,379 So I will duplicate this code. 71 00:06:36,160 --> 00:06:38,600 If I right-click here, I have the possibility of duplicate, 72 00:06:39,480 --> 00:06:42,060 and I will click and drag here. 73 00:06:42,560 --> 00:06:45,000 This second if is inside the first if. 74 00:06:45,120 --> 00:06:45,899 Can you see the structure? 75 00:06:46,459 --> 00:06:51,740 But now, instead of comparing with 13, I'm going to compare with 12, 76 00:06:51,740 --> 00:06:56,819 And now, if output equals 12, number 12 will be hide. 77 00:06:57,199 --> 00:06:59,379 The same for 11. 78 00:07:00,920 --> 00:07:05,639 If output equals 11, 11 will be hide. 79 00:07:07,220 --> 00:07:11,709 And I'm going to duplicate again, duplicate. 80 00:07:13,009 --> 00:07:14,430 No, not here, I made a mistake. 81 00:07:14,629 --> 00:07:16,949 This one has not to be here, it has to be here. 82 00:07:17,009 --> 00:07:17,689 Can you see the difference? 83 00:07:18,649 --> 00:07:26,410 Now, if output equals 10, number 10 is the one that's going to be high. 84 00:07:26,910 --> 00:07:28,329 All of them are here. 85 00:07:28,329 --> 00:07:33,829 It means if I press the button, one of these three possibilities will be true 86 00:07:33,829 --> 00:07:41,889 and one of these connectors will be high and the LED connected to it will shine. 87 00:07:42,730 --> 00:07:47,089 But what happens if the input is not high? 88 00:07:47,089 --> 00:07:57,089 If I'm not pressing the button, really easy, as you can guess, we will have four LEDs that are low. 89 00:07:57,529 --> 00:08:03,269 13, sorry, be careful when you click and drag the block. 90 00:08:04,730 --> 00:08:12,399 12, 11, I'm duplicating all the time. 91 00:08:13,139 --> 00:08:15,079 And 10, here's 10. 92 00:08:15,079 --> 00:08:21,560 So, if I don't press the button, it means this condition is not true, we go to the C 93 00:08:21,560 --> 00:08:24,959 no, the else condition, and the four of them are low. 94 00:08:24,959 --> 00:08:33,360 And the random number has to be here, with these four blocks. 95 00:08:33,360 --> 00:08:42,379 Everything has been programmed properly, everything has been connected properly, so I can start 96 00:08:42,379 --> 00:08:43,519 the simulation. 97 00:08:43,519 --> 00:08:49,960 If I click on the button, ok, everything is working, nothing happens because I'm not pressing 98 00:08:49,960 --> 00:08:54,299 the button, but if I press the button, one of them is shining, ok? 99 00:08:54,299 --> 00:08:57,340 If I not press, none of them shines. 100 00:08:57,340 --> 00:09:05,700 If I press again, another one is shining, again and again and again and again, but realize 101 00:09:05,700 --> 00:09:11,419 that I cannot guess which one is going to shine because it's a random process, ok? 102 00:09:11,419 --> 00:09:13,799 So, okay, this is the circuit. 103 00:09:13,799 --> 00:09:18,799 We are going to connect and to program today, okay? 104 00:09:20,059 --> 00:09:20,899 Good luck.