1 00:00:00,270 --> 00:00:05,760 Hello. In this exercise we are 2 00:00:05,760 --> 00:00:08,370 going to reuse a previous circuit the 3 00:00:08,370 --> 00:00:10,470 one that we made with the digital 4 00:00:10,530 --> 00:00:13,080 input so here we can find all 5 00:00:13,080 --> 00:00:15,420 the circuits that we've already made and 6 00:00:15,420 --> 00:00:18,210 we can duplicate whichever we choose for 7 00:00:18,210 --> 00:00:19,890 instance since we're going to use a 8 00:00:19,890 --> 00:00:20,160 digital 9 00:00:20,160 --> 00:00:22,260 input we click on the wheel 10 00:00:22,260 --> 00:00:25,890 here and then we can duplicate it 11 00:00:25,890 --> 00:00:26,880 or copy it 12 00:00:30,480 --> 00:00:31,710 if we wait a second 13 00:00:33,360 --> 00:00:35,070 then a copy of the circuit will 14 00:00:35,070 --> 00:00:37,650 appear now in this exercise we're going 15 00:00:37,650 --> 00:00:40,080 to use almost the same connections we 16 00:00:40,080 --> 00:00:41,910 are going to use the digital input 17 00:00:41,910 --> 00:00:44,790 with a button and the pull-down resistor 18 00:00:45,240 --> 00:00:46,860 and we're going to use LED 19 00:00:46,860 --> 00:00:49,560 as output but here instead of having 20 00:00:49,560 --> 00:00:51,090 just one of them we're going to 21 00:00:51,090 --> 00:00:52,260 use four of them 22 00:00:53,130 --> 00:00:54,240 so the first thing we need to 23 00:00:54,240 --> 00:00:55,440 do is make a little bit of 24 00:00:55,440 --> 00:00:57,330 room so I'm going to click and 25 00:00:57,330 --> 00:01:00,300 drag the button over and then the 26 00:01:00,300 --> 00:01:04,080 wire and the pull-down resistor remember that 27 00:01:04,080 --> 00:01:06,360 this is a ten kilo ohms one 28 00:01:07,770 --> 00:01:09,450 and I'm going to click and drag 29 00:01:09,480 --> 00:01:10,410 the input wire 30 00:01:12,210 --> 00:01:14,340 I'm going to use pin numbers thirteen 31 00:01:14,430 --> 00:01:16,980 twelve eleven and ten to control the 32 00:01:16,980 --> 00:01:19,470 four LED so I'm going to 33 00:01:19,470 --> 00:01:22,590 click and drag the input wire from 34 00:01:22,650 --> 00:01:24,840 the button to number nine 35 00:01:26,010 --> 00:01:27,360 and now I'm going to click and 36 00:01:27,360 --> 00:01:29,640 drag the four LED just by 37 00:01:29,640 --> 00:01:31,470 adding three more to the one that 38 00:01:31,470 --> 00:01:32,040 we have 39 00:01:37,410 --> 00:01:39,360 therefore I will also need three more 40 00:01:39,360 --> 00:01:40,260 resistors 41 00:01:41,670 --> 00:01:43,380 and remember all of them are connected 42 00:01:43,380 --> 00:01:44,970 to the anode the pin that is 43 00:01:44,970 --> 00:01:45,690 not straight 44 00:01:49,020 --> 00:01:51,300 now remember for the LED we 45 00:01:51,300 --> 00:01:52,800 need to change these values to be 46 00:01:52,800 --> 00:01:54,810 two thousand two hundred and twenty ohms 47 00:01:55,260 --> 00:01:56,760 because this is the value that we 48 00:01:56,760 --> 00:01:59,910 need to protect the LED and remember 49 00:01:59,910 --> 00:02:02,190 that ohms and kilo ohms are not 50 00:02:02,250 --> 00:02:03,150 the same thing 51 00:02:12,630 --> 00:02:14,460 so now I'm going to connect the 52 00:02:14,460 --> 00:02:17,340 LED using the wires and the 53 00:02:17,340 --> 00:02:19,680 first connection I want is to make 54 00:02:19,680 --> 00:02:21,660 the four black wires that are connected 55 00:02:21,660 --> 00:02:22,620 to the ground 56 00:02:24,000 --> 00:02:25,800 we'll make them all black like always 57 00:02:31,230 --> 00:02:33,630 and be careful when you draw the 58 00:02:33,630 --> 00:02:36,720 wires because sometimes you make a mistake 59 00:02:36,720 --> 00:02:38,310 and you don't realize that you've made 60 00:02:38,310 --> 00:02:40,200 a mistake so you can just delete 61 00:02:40,200 --> 00:02:40,560 what 62 00:02:42,480 --> 00:02:43,080 what you do 63 00:02:44,400 --> 00:02:45,150 and start over 64 00:02:46,500 --> 00:02:47,910 okay so now I have a single 65 00:02:47,910 --> 00:02:50,370 wire and these four wires are connected 66 00:02:50,370 --> 00:02:53,100 to the ground because of this horizontal 67 00:02:53,100 --> 00:02:55,260 line you see that the horizontal line 68 00:02:55,260 --> 00:02:56,700 is connected to the ground through these 69 00:02:56,700 --> 00:03:00,210 wires and now I need a connection 70 00:03:00,240 --> 00:03:03,900 from twelve to this one from eleven 71 00:03:03,930 --> 00:03:06,420 to this one from ten 72 00:03:07,020 --> 00:03:09,159 to this one and now that I 73 00:03:09,159 --> 00:03:10,620 have everything I need with all the 74 00:03:10,620 --> 00:03:11,310 components 75 00:03:12,660 --> 00:03:14,670 so now I need to program the 76 00:03:14,670 --> 00:03:16,740 circuit so I'm going to open the 77 00:03:16,740 --> 00:03:19,560 coding window and we just want to 78 00:03:19,560 --> 00:03:22,200 modify the program we already have because 79 00:03:22,860 --> 00:03:24,810 some of the possibilities and ideas are 80 00:03:24,810 --> 00:03:26,100 the same so I'm not going to 81 00:03:26,100 --> 00:03:27,120 get rid of all of it 82 00:03:29,550 --> 00:03:31,470 and again I'm reading the input for 83 00:03:31,470 --> 00:03:34,140 number nine so instead of reading from 84 00:03:34,140 --> 00:03:36,630 number twelve now I'm reading from nine 85 00:03:36,660 --> 00:03:38,670 so we modify that here 86 00:03:40,170 --> 00:03:41,820 so I have a variable that I 87 00:03:41,820 --> 00:03:43,860 read from number nine and it's stored 88 00:03:43,860 --> 00:03:47,280 in this variable so if this variable 89 00:03:47,280 --> 00:03:49,740 or input is high then something would 90 00:03:49,740 --> 00:03:52,110 happen here and if the input is 91 00:03:52,200 --> 00:03:55,500 not high then something else will happen 92 00:03:55,500 --> 00:03:56,820 down here that will program 93 00:03:58,470 --> 00:03:59,700 so the first thing we need is 94 00:03:59,700 --> 00:04:02,490 a random number so if we go 95 00:04:02,490 --> 00:04:05,580 to the green library about math there 96 00:04:05,610 --> 00:04:08,490 is a block here related to random 97 00:04:08,490 --> 00:04:10,950 numbers that allows us to generate one 98 00:04:11,280 --> 00:04:14,040 from a range now I want a 99 00:04:14,040 --> 00:04:16,110 random number from ten 100 00:04:17,310 --> 00:04:19,920 two thirteen because these are our LED 101 00:04:19,920 --> 00:04:22,140 connector pin numbers so it has 102 00:04:22,140 --> 00:04:23,640 to be somewhere between these four 103 00:04:26,190 --> 00:04:28,350 I also realize that there is a 104 00:04:28,350 --> 00:04:30,000 bar down here so if it looks 105 00:04:30,000 --> 00:04:31,560 like there's not enough room just click 106 00:04:31,560 --> 00:04:33,660 and drag this and you can see 107 00:04:33,660 --> 00:04:34,140 everything 108 00:04:45,390 --> 00:04:47,460 now there's one more thing I almost 109 00:04:47,460 --> 00:04:49,620 forgot before we move on is that 110 00:04:49,620 --> 00:04:51,240 if I have a random number here 111 00:04:51,240 --> 00:04:53,220 I still need to store it somewhere 112 00:04:53,970 --> 00:04:56,250 so I'm going to create a new 113 00:04:56,280 --> 00:04:59,400 variable under variables we can name it 114 00:04:59,400 --> 00:05:01,980 anything we want but I'm going to 115 00:05:01,980 --> 00:05:05,280 use output because this random number will 116 00:05:05,280 --> 00:05:05,477 be 117 00:05:05,520 --> 00:05:07,320 the output that will make the LED 118 00:05:07,320 --> 00:05:09,990 shine so just like we did before 119 00:05:10,020 --> 00:05:12,270 I'm going to define output using this 120 00:05:12,300 --> 00:05:16,020 random number so output will have a 121 00:05:16,020 --> 00:05:18,300 random number from ten to thirteen 122 00:05:21,480 --> 00:05:23,940 okay so what happens if I press 123 00:05:23,940 --> 00:05:26,070 the button is one of the LED 124 00:05:26,070 --> 00:05:28,620 these will shine well which one 125 00:05:29,880 --> 00:05:31,740 it just depends on the random number 126 00:05:31,740 --> 00:05:32,340 generated 127 00:05:34,860 --> 00:05:36,600 so I have to check the value 128 00:05:36,600 --> 00:05:39,150 of the output now to do this 129 00:05:39,240 --> 00:05:41,790 I'm going to use the comparison block 130 00:05:41,790 --> 00:05:42,180 again 131 00:05:43,350 --> 00:05:45,690 we will use the equal sign and 132 00:05:45,690 --> 00:05:47,100 I want to check the value of 133 00:05:47,100 --> 00:05:50,370 the output so for instance if output 134 00:05:50,370 --> 00:05:55,080 equals thirteen then something will happen but 135 00:05:55,080 --> 00:05:56,610 I also need a block for the 136 00:05:56,610 --> 00:05:59,670 if so now I'm comparing if the 137 00:05:59,670 --> 00:06:02,100 output that is the random number equals 138 00:06:02,100 --> 00:06:02,790 thirteen 139 00:06:03,900 --> 00:06:07,170 then what will happen will then output 140 00:06:07,170 --> 00:06:09,780 number thirteen will be high and this 141 00:06:09,780 --> 00:06:12,120 block will be here inside the first 142 00:06:12,240 --> 00:06:15,240 if because if the input or the 143 00:06:15,240 --> 00:06:17,310 one we are reading here is high 144 00:06:17,970 --> 00:06:20,760 and the output is thirteen then number 145 00:06:20,760 --> 00:06:22,170 thirteen will shine 146 00:06:29,880 --> 00:06:31,110 so do you see this and 147 00:06:31,110 --> 00:06:33,180 then if it generates for a random 148 00:06:33,180 --> 00:06:37,290 number thirteen the same happens for twelve 149 00:06:37,620 --> 00:06:40,080 eleven and ten so I will duplicate 150 00:06:40,080 --> 00:06:42,480 the same code and put it again 151 00:06:42,480 --> 00:06:43,440 in the subset 152 00:06:45,600 --> 00:06:48,480 so the second if condition is inside 153 00:06:48,480 --> 00:06:49,920 the first if condition 154 00:06:52,200 --> 00:06:54,270 but now instead of comparing with thirteen 155 00:06:54,300 --> 00:06:56,580 I'm going to compare with twelve and 156 00:06:56,580 --> 00:06:58,500 now if output equals twelve twelve will 157 00:06:58,500 --> 00:06:59,070 be high 158 00:07:00,690 --> 00:07:03,750 then duplicate again for number eleven if 159 00:07:03,750 --> 00:07:05,940 the output is eleven then eleven will 160 00:07:05,940 --> 00:07:06,570 be high 161 00:07:09,750 --> 00:07:12,300 and duplicate again for our last pin 162 00:07:13,500 --> 00:07:14,370 for number ten 163 00:07:18,270 --> 00:07:19,500 you see I almost put that in 164 00:07:19,500 --> 00:07:21,240 the wrong place but this one has 165 00:07:21,240 --> 00:07:23,550 to be connected to the others so 166 00:07:23,550 --> 00:07:26,250 now if output equals ten number ten 167 00:07:26,250 --> 00:07:27,120 is the one that's going to be 168 00:07:27,120 --> 00:07:29,280 high all of them are here so 169 00:07:29,280 --> 00:07:30,810 it means if I press the button 170 00:07:31,020 --> 00:07:33,420 one of these possibilities will be true 171 00:07:33,720 --> 00:07:35,670 one of these connectors will be high 172 00:07:35,910 --> 00:07:38,010 and the LED connected to that number 173 00:07:38,010 --> 00:07:38,610 will shine 174 00:07:40,770 --> 00:07:42,480 but what happens if the input is 175 00:07:42,480 --> 00:07:44,130 not high if i'm not pressing the 176 00:07:44,130 --> 00:07:46,620 button you can probably guess that we 177 00:07:46,620 --> 00:07:48,300 will have all four LED that 178 00:07:48,300 --> 00:07:51,420 are low so these are under the 179 00:07:51,480 --> 00:07:56,040 if not condition so let's add thirteen 180 00:07:56,520 --> 00:07:57,120 twelve 181 00:07:58,920 --> 00:08:00,240 eleven and ten 182 00:08:10,860 --> 00:08:11,700 eleven 183 00:08:13,800 --> 00:08:15,750 and ten so if I don't press 184 00:08:15,750 --> 00:08:17,550 the button it means that this condition 185 00:08:17,550 --> 00:08:19,620 is not true and it will go 186 00:08:19,620 --> 00:08:21,690 to the if not condition and all 187 00:08:21,690 --> 00:08:23,640 four will be low and the random 188 00:08:23,640 --> 00:08:25,350 number has to be here connected to 189 00:08:25,350 --> 00:08:26,400 these four blocks 190 00:08:29,400 --> 00:08:31,710 so now everything has been programmed and 191 00:08:31,710 --> 00:08:33,990 connected properly you see 192 00:08:44,010 --> 00:08:45,750 so I can start the simulation 193 00:08:46,980 --> 00:08:48,810 and if I click on the button 194 00:08:48,870 --> 00:08:52,830 of course nothing happens because I am 195 00:08:52,830 --> 00:08:54,450 not pressing the button but if I 196 00:08:54,450 --> 00:08:57,390 am then one of them will shine 197 00:08:57,900 --> 00:09:00,210 if I release they are off and 198 00:09:00,210 --> 00:09:02,130 if I press again another one will 199 00:09:02,130 --> 00:09:04,080 shine you can press it over and 200 00:09:04,080 --> 00:09:05,850 over but we can't guess which one 201 00:09:05,850 --> 00:09:06,960 is going to shine because 202 00:09:06,960 --> 00:09:08,580 as we programmed it to be random 203 00:09:09,030 --> 00:09:11,070 okay this is the circuit you will 204 00:09:11,070 --> 00:09:13,500 now connect and program today good luck