1 00:00:02,280 --> 00:00:04,530 hello today we are going to program 2 00:00:04,530 --> 00:00:06,840 a new circuit similar to the ones 3 00:00:06,840 --> 00:00:09,690 we've already programmed so we will use 4 00:00:09,690 --> 00:00:12,030 a protoboard and arduino board as 5 00:00:12,030 --> 00:00:15,360 always and click and drag three LED 6 00:00:22,920 --> 00:00:24,540 we're going to connect them in a 7 00:00:24,540 --> 00:00:27,000 similar way that we've connected them before 8 00:00:27,330 --> 00:00:29,820 so we use a black wire to 9 00:00:29,820 --> 00:00:30,900 connect it to the ground 10 00:00:32,549 --> 00:00:34,050 and then of course we need three 11 00:00:34,050 --> 00:00:35,400 protection resistors 12 00:00:40,680 --> 00:00:43,440 and remember that each protection resistor all 13 00:00:43,440 --> 00:00:45,600 three are going to be two hundred 14 00:00:45,630 --> 00:00:48,600 and twenty ohms not kilo ohms 15 00:00:50,670 --> 00:00:52,980 and they're connected to the cathode or 16 00:00:52,980 --> 00:00:54,000 the straight side 17 00:01:06,570 --> 00:01:09,330 okay so these three LED are going 18 00:01:09,330 --> 00:01:13,560 to be connected to connectors thirteen twelve 19 00:01:14,010 --> 00:01:15,000 and eleven 20 00:01:17,130 --> 00:01:19,230 okay so these three LED are going 21 00:01:19,230 --> 00:01:20,430 to be our output 22 00:01:22,350 --> 00:01:24,000 now the new part today is that 23 00:01:24,000 --> 00:01:25,620 we're going to learn to use two 24 00:01:25,650 --> 00:01:28,320 switches because we want to use two 25 00:01:28,380 --> 00:01:31,200 digital inputs so we're going to use 26 00:01:31,200 --> 00:01:32,640 connector ten 27 00:01:37,620 --> 00:01:38,160 and nine 28 00:01:40,140 --> 00:01:41,280 so we add the switches 29 00:01:43,650 --> 00:01:45,540 and then from connector ten we're going 30 00:01:45,540 --> 00:01:47,280 to make this wire orange 31 00:01:51,210 --> 00:01:52,950 and an orange wire again for the 32 00:01:52,950 --> 00:01:53,940 second switch 33 00:01:57,240 --> 00:01:59,340 remember that we're going to connect a 34 00:01:59,340 --> 00:02:01,828 pull-down resistor so when we used the 35 00:02:01,828 --> 00:02:04,740 single button it was a ten kilo 36 00:02:04,740 --> 00:02:08,669 ohms pull down resistor so let's add 37 00:02:09,210 --> 00:02:11,250 one to each switch and change it 38 00:02:11,250 --> 00:02:12,570 to ten kilo ohms 39 00:02:18,510 --> 00:02:20,070 and these are actually going to be 40 00:02:20,070 --> 00:02:21,900 put into the center of the switches 41 00:02:21,900 --> 00:02:23,010 sorry let's move these 42 00:02:29,280 --> 00:02:30,930 and then we also need a five 43 00:02:30,960 --> 00:02:33,390 volts connector so we are going to 44 00:02:33,390 --> 00:02:35,250 connect the wire all the way down 45 00:02:35,250 --> 00:02:36,330 from five volts 46 00:02:38,850 --> 00:02:41,040 to this line and it'll be read 47 00:02:42,600 --> 00:02:44,670 now I need another red connection here 48 00:02:44,670 --> 00:02:46,943 because I want five volts to this 49 00:02:46,943 --> 00:02:49,350 switch and the same with this one 50 00:02:53,940 --> 00:02:55,440 and remember to connect it to the 51 00:02:55,440 --> 00:02:58,080 same horizontal line that the five foot 52 00:02:58,080 --> 00:03:00,540 wire is on sometimes we make mistakes 53 00:03:00,540 --> 00:03:02,550 connecting wires and then the circuits don't 54 00:03:02,550 --> 00:03:04,230 work but it's actually not related to 55 00:03:04,230 --> 00:03:06,510 the programming it's just because of an 56 00:03:06,510 --> 00:03:08,910 improper wire connection so make sure they're 57 00:03:08,910 --> 00:03:10,110 always connected properly 58 00:03:11,610 --> 00:03:13,890 so instead of having the button like 59 00:03:13,890 --> 00:03:17,340 before I have two switches why because 60 00:03:17,340 --> 00:03:19,410 we will manipulate them so that when 61 00:03:19,410 --> 00:03:21,330 I press one of them i'll have 62 00:03:21,330 --> 00:03:24,390 a single pointer single connection so if 63 00:03:24,390 --> 00:03:26,280 I want to press the other one 64 00:03:26,280 --> 00:03:27,900 I can't be pressing both at the 65 00:03:27,900 --> 00:03:30,120 same time that's why I'm using a 66 00:03:30,120 --> 00:03:30,720 switch 67 00:03:30,840 --> 00:03:34,020 because remember when we discussed components we 68 00:03:34,020 --> 00:03:36,690 said that switches have two permanent states 69 00:03:36,780 --> 00:03:39,150 on and off that's why we need 70 00:03:39,150 --> 00:03:42,360 two switches instead of two buttons because 71 00:03:42,360 --> 00:03:43,530 if we use a button then the 72 00:03:43,530 --> 00:03:46,200 moment we finish pressing the connection is 73 00:03:46,200 --> 00:03:46,920 closed 74 00:03:49,140 --> 00:03:49,530 okay 75 00:03:51,270 --> 00:03:52,410 so that's why we're going to use 76 00:03:52,470 --> 00:03:54,150 two switches and it'll make a lot 77 00:03:54,150 --> 00:03:55,920 more sense when we see the simulation 78 00:03:55,920 --> 00:03:56,310 later 79 00:03:58,950 --> 00:04:00,870 so this switch is connected the same 80 00:04:00,870 --> 00:04:03,060 way the button has been connected and 81 00:04:03,060 --> 00:04:06,120 now there's no connection between this point 82 00:04:06,240 --> 00:04:07,140 and this point 83 00:04:08,940 --> 00:04:10,620 okay you can see this position so 84 00:04:10,620 --> 00:04:12,870 here this wire is connected to the 85 00:04:12,870 --> 00:04:16,230 ground through the pull-down resistor and then 86 00:04:16,230 --> 00:04:18,209 the moment that there's a connection between 87 00:04:18,209 --> 00:04:20,940 the orange and the red wires I 88 00:04:20,940 --> 00:04:22,650 have five volts from here and then 89 00:04:22,650 --> 00:04:24,750 the five volts will be in connectors 90 00:04:24,780 --> 00:04:26,880 ten and the same for number nine 91 00:04:34,950 --> 00:04:37,500 now for this simulation i'm going to 92 00:04:37,500 --> 00:04:39,030 simulate the circuit this way 93 00:04:40,740 --> 00:04:43,470 let's code and I'm going to program 94 00:04:43,470 --> 00:04:44,670 it step by step 95 00:04:46,080 --> 00:04:47,580 the first thing I need are two 96 00:04:47,580 --> 00:04:48,420 variables 97 00:04:50,970 --> 00:04:54,270 I'm going to name them input nine 98 00:04:54,330 --> 00:04:56,700 and input ten because we're reading two 99 00:04:56,700 --> 00:04:58,110 inputs from those numbers 100 00:05:03,480 --> 00:05:04,140 input ten 101 00:05:06,565 --> 00:05:08,550 now right now I haven't said anything 102 00:05:08,550 --> 00:05:10,920 about the behavior of the arduino board 103 00:05:10,920 --> 00:05:12,390 or the circuit and I'm going to 104 00:05:12,390 --> 00:05:15,240 explain it while I'm programming so if 105 00:05:15,240 --> 00:05:17,370 you think you miss something I just 106 00:05:17,370 --> 00:05:18,390 haven't gotten there yet 107 00:05:21,450 --> 00:05:22,860 now the first thing we're gonna do 108 00:05:22,860 --> 00:05:26,310 is read numbers nine and ten so 109 00:05:26,310 --> 00:05:28,320 let's find them here and we're going 110 00:05:28,320 --> 00:05:29,730 to read nine 111 00:05:31,770 --> 00:05:32,790 and again with ten 112 00:05:37,650 --> 00:05:39,120 now we're going to use these readings 113 00:05:39,120 --> 00:05:42,600 to define input nine and input ten 114 00:05:42,930 --> 00:05:44,520 it means that we're reading these two 115 00:05:44,520 --> 00:05:47,280 connectors and we are storing their values 116 00:05:47,310 --> 00:05:50,670 into variables remember that variables are like 117 00:05:50,670 --> 00:05:53,070 boxes and we store the values inside 118 00:05:53,070 --> 00:05:53,430 of them 119 00:05:54,210 --> 00:05:55,920 so here we are going to store 120 00:05:55,980 --> 00:05:58,230 high or low depending on whether the 121 00:05:58,230 --> 00:06:00,210 switch is on or off 122 00:06:05,220 --> 00:06:06,510 and now we can move on to 123 00:06:06,510 --> 00:06:09,780 the behavior so first of all I 124 00:06:09,780 --> 00:06:12,990 need an if condition "si" remember if 125 00:06:14,010 --> 00:06:16,050 now we have four possibilities here 126 00:06:17,310 --> 00:06:19,230 with two switches they can either be 127 00:06:19,230 --> 00:06:20,310 both on 128 00:06:21,480 --> 00:06:24,990 both off or the first one on 129 00:06:25,890 --> 00:06:27,930 and the second one off or the 130 00:06:27,930 --> 00:06:29,490 first one off and the second one 131 00:06:29,520 --> 00:06:31,740 on so I need to if or 132 00:06:31,740 --> 00:06:35,880 see sections and therefore possibilities now to 133 00:06:35,880 --> 00:06:39,870 compare we already know the sine equals 134 00:06:40,230 --> 00:06:41,490 in the previous exercise 135 00:06:41,580 --> 00:06:43,170 we've used that so I need to 136 00:06:43,170 --> 00:06:45,150 have them here because I'm going to 137 00:06:45,150 --> 00:06:46,800 use the and connector 138 00:06:49,170 --> 00:06:50,760 so let's add two equals 139 00:06:57,060 --> 00:06:58,560 and then we want to eat or 140 00:06:58,590 --> 00:07:00,720 and to compare them 141 00:07:01,980 --> 00:07:03,240 and put them together let's make it 142 00:07:03,240 --> 00:07:04,740 smaller so it's easier to see 143 00:07:06,060 --> 00:07:08,010 now there are two possibilities okay the 144 00:07:08,010 --> 00:07:10,950 first possibility is that number nine will 145 00:07:10,950 --> 00:07:14,790 be low or off and another possibility 146 00:07:14,790 --> 00:07:17,010 is number ten is low or off 147 00:07:17,850 --> 00:07:19,800 if nine is often ten is off 148 00:07:19,860 --> 00:07:22,350 I'm going to use the and block 149 00:07:22,410 --> 00:07:24,150 to combine both of them 150 00:07:31,560 --> 00:07:33,090 so they can both be off now 151 00:07:33,090 --> 00:07:35,850 let's combine them into this one big 152 00:07:35,880 --> 00:07:39,390 and block we want the whole thing 153 00:07:40,290 --> 00:07:41,250 and drag it over here 154 00:07:45,120 --> 00:07:47,040 so I'm using this condition instead of 155 00:07:47,040 --> 00:07:50,100 one single condition and combining them okay 156 00:07:50,190 --> 00:07:52,050 this is the purpose of the exercise 157 00:07:52,050 --> 00:07:54,570 is to combine two different conditions and 158 00:07:54,570 --> 00:07:56,520 that's why we have two different inputs 159 00:08:00,240 --> 00:08:01,980 so what do I want if both 160 00:08:01,980 --> 00:08:04,110 of them are off well we can 161 00:08:04,110 --> 00:08:05,550 consider that if both of them are 162 00:08:05,550 --> 00:08:09,030 low then thirteen twelve and eleven are 163 00:08:09,030 --> 00:08:09,900 low as well 164 00:08:11,130 --> 00:08:13,740 those lights so we'll use three blocks 165 00:08:13,740 --> 00:08:14,220 in a row 166 00:08:20,580 --> 00:08:21,810 one for each lcd 167 00:08:27,120 --> 00:08:28,560 make sure they're in the correct place 168 00:08:28,560 --> 00:08:29,820 all connected to each other 169 00:08:31,530 --> 00:08:33,210 so if nine and ten are off 170 00:08:33,240 --> 00:08:35,070 I'm going to decide for my program 171 00:08:35,070 --> 00:08:37,620 that thirteen twelve and eleven eli these 172 00:08:37,860 --> 00:08:40,470 are all low why because that's just 173 00:08:40,620 --> 00:08:42,840 what I want for the program so 174 00:08:42,840 --> 00:08:46,620 let's do thirteen twelve and eleven 175 00:08:47,760 --> 00:08:48,210 although 176 00:08:54,480 --> 00:08:56,391 okay what else do I want well 177 00:08:56,391 --> 00:08:58,140 I can just remove these three and 178 00:08:58,140 --> 00:09:00,120 actually copy what we already have because 179 00:09:00,120 --> 00:09:01,140 it's easier this way 180 00:09:03,540 --> 00:09:06,660 so down here what happens if nine 181 00:09:07,020 --> 00:09:09,480 is hide number switch nine as high 182 00:09:09,480 --> 00:09:11,850 and ten is low well what do 183 00:09:11,850 --> 00:09:13,950 we want let's just say that we 184 00:09:13,950 --> 00:09:16,140 would like thirteen to be high why 185 00:09:16,140 --> 00:09:16,410 not 186 00:09:17,550 --> 00:09:20,160 so if we press this one thirteen 187 00:09:20,160 --> 00:09:20,760 will be high 188 00:09:23,340 --> 00:09:25,980 okay that's the second possibility now what 189 00:09:25,980 --> 00:09:28,950 happens if nine is low or off 190 00:09:28,950 --> 00:09:31,500 and ten is high or on it 191 00:09:31,500 --> 00:09:33,270 means that if we're pressing this one 192 00:09:33,270 --> 00:09:35,100 if ten is the only one that's 193 00:09:35,100 --> 00:09:35,640 on 194 00:09:37,140 --> 00:09:39,660 then let's say eleven is high so 195 00:09:39,660 --> 00:09:41,580 eleven will shine it'll be high 196 00:09:44,340 --> 00:09:45,270 this is just how I'm going to 197 00:09:45,270 --> 00:09:48,660 decide to program this this time this 198 00:09:48,660 --> 00:09:48,930 way 199 00:09:51,720 --> 00:09:53,520 now what happens if both of them 200 00:09:53,520 --> 00:09:55,770 nine and ten are high or an 201 00:09:56,700 --> 00:09:58,620 ok we'll just because we want we 202 00:09:58,620 --> 00:10:01,050 can try to program a blinking series 203 00:10:01,080 --> 00:10:02,490 like we did before so we're going 204 00:10:02,490 --> 00:10:04,410 to program a blink the way that 205 00:10:04,410 --> 00:10:05,730 we know how to do it 206 00:10:07,375 --> 00:10:08,365 it can duplicate 207 00:10:11,905 --> 00:10:14,215 and remember that we need the wait 208 00:10:14,935 --> 00:10:15,505 code 209 00:10:20,845 --> 00:10:22,465 so duplicate this 210 00:10:29,815 --> 00:10:32,545 and add the wait for the blinking 211 00:10:35,305 --> 00:10:37,435 duplicate again and I'll have them all 212 00:10:37,495 --> 00:10:41,185 low after waiting so shining on that 213 00:10:41,185 --> 00:10:42,475 loop of on and off 214 00:10:44,605 --> 00:10:45,835 okay do you see that have both 215 00:10:45,835 --> 00:10:47,065 of them are low if both of 216 00:10:47,065 --> 00:10:48,475 them are off then it's a blinking 217 00:10:48,475 --> 00:10:50,995 program so realize that there are four 218 00:10:51,055 --> 00:10:53,125 if blocks for each part because we 219 00:10:53,125 --> 00:10:56,425 still only have four possibilities low and 220 00:10:56,425 --> 00:10:59,875 low low and high high end low 221 00:11:00,325 --> 00:11:03,055 and high and high and for every 222 00:11:03,055 --> 00:11:03,758 possibility 223 00:11:03,775 --> 00:11:06,205 I haven't programmed a different behavior so 224 00:11:06,205 --> 00:11:08,065 now let's see if it works the 225 00:11:08,065 --> 00:11:09,595 way that we've programmed okay 226 00:11:13,495 --> 00:11:15,625 so start the simulation and both switches 227 00:11:15,625 --> 00:11:16,285 are off 228 00:11:22,495 --> 00:11:25,675 another appears to be a mistake somewhere 229 00:11:25,675 --> 00:11:27,205 after switching this on 230 00:11:31,075 --> 00:11:33,385 ok it's a problem with the liars 231 00:11:33,715 --> 00:11:35,875 were missing our ground connection so be 232 00:11:35,935 --> 00:11:39,295 careful with the ground we always need 233 00:11:39,295 --> 00:11:41,725 to include that for our ladies 234 00:11:45,445 --> 00:11:46,945 okay now can you see that all 235 00:11:46,945 --> 00:11:49,105 three are connected to the ground and 236 00:11:49,105 --> 00:11:51,265 now that the circuit is closed and 237 00:11:51,265 --> 00:11:54,565 everything should work so let's start again 238 00:11:59,605 --> 00:12:04,435 okay so again i think there's a 239 00:12:04,435 --> 00:12:06,565 problem with the connection so let's see 240 00:12:06,565 --> 00:12:08,125 if we can find the problem 241 00:12:11,935 --> 00:12:13,945 ah no actually there is no problem 242 00:12:13,945 --> 00:12:15,835 because it is running according to the 243 00:12:15,835 --> 00:12:18,445 program so if the two of them 244 00:12:18,445 --> 00:12:19,945 are low then there is a blink 245 00:12:20,215 --> 00:12:22,105 it makes sense if the two of 246 00:12:22,105 --> 00:12:23,485 them are high 247 00:12:24,895 --> 00:12:27,145 and and we can scroll back up 248 00:12:27,145 --> 00:12:27,685 here 249 00:12:37,435 --> 00:12:39,385 hmm okay so I made a mistake 250 00:12:39,385 --> 00:12:40,975 with the program so I'm going to 251 00:12:40,975 --> 00:12:43,525 check it again low and low and 252 00:12:43,525 --> 00:12:45,205 the last part is high and high 253 00:12:47,395 --> 00:12:49,345 okay now if both of them are 254 00:12:49,345 --> 00:12:51,445 switched on we want the blink 255 00:12:53,545 --> 00:12:55,195 if both of them are off then 256 00:12:55,195 --> 00:12:56,125 the lights are low 257 00:12:59,785 --> 00:13:01,405 there we go so on is when 258 00:13:01,405 --> 00:13:02,965 we want the blank ok now it's 259 00:13:02,965 --> 00:13:03,325 right 260 00:13:05,455 --> 00:13:06,955 so it's important that when you program 261 00:13:06,955 --> 00:13:09,145 you check the behavior of your programming 262 00:13:09,505 --> 00:13:11,185 making mistakes is not a problem but 263 00:13:11,185 --> 00:13:13,795 just check the work okay so now 264 00:13:13,795 --> 00:13:15,055 the two of them are off 265 00:13:16,375 --> 00:13:18,295 nothing happens and they're low 266 00:13:21,385 --> 00:13:23,185 if I press the first one 267 00:13:24,805 --> 00:13:25,675 this one is ten 268 00:13:26,995 --> 00:13:28,195 the two of them are high 269 00:13:31,375 --> 00:13:33,565 these two now I'm going to modify 270 00:13:33,565 --> 00:13:35,425 it so that just eleven is high 271 00:13:35,425 --> 00:13:36,145 instead 272 00:13:37,975 --> 00:13:38,965 so go over here 273 00:13:40,855 --> 00:13:41,935 to our tennis high 274 00:13:47,215 --> 00:13:49,525 and just eleven will be high instead 275 00:13:52,645 --> 00:13:54,175 so can you see the difference now 276 00:13:54,415 --> 00:13:56,335 and let's start the simulation again and 277 00:13:56,335 --> 00:13:57,865 now both of them are off and 278 00:13:57,865 --> 00:13:58,855 nothing happens 279 00:14:01,225 --> 00:14:02,575 and if I press this one then 280 00:14:02,575 --> 00:14:04,525 the shining perfect so it's according to 281 00:14:04,525 --> 00:14:07,255 the program if just the second one 282 00:14:07,255 --> 00:14:09,685 is on then this one is shining 283 00:14:09,685 --> 00:14:12,265 perfect just like we programmed and if 284 00:14:12,265 --> 00:14:13,795 both of them are on we have 285 00:14:13,795 --> 00:14:16,525 the blinking program so it works the 286 00:14:16,525 --> 00:14:19,195 circuit behaves according to the program now 287 00:14:19,195 --> 00:14:20,095 we've made some mist 288 00:14:20,095 --> 00:14:21,865 stakes but that's not a big problem 289 00:14:21,865 --> 00:14:23,545 because we can always check and then 290 00:14:23,545 --> 00:14:27,505 compare our behavior with our program to 291 00:14:27,505 --> 00:14:29,155 the same way that when you simulate 292 00:14:29,155 --> 00:14:31,465 the circuit you can check the behavior 293 00:14:31,465 --> 00:14:34,525 to that we've connected everything okay so 294 00:14:34,525 --> 00:14:35,905 I will repeat this circuit 295 00:14:37,615 --> 00:14:40,945 if nothing is connected then nothing happens 296 00:14:41,365 --> 00:14:43,465 if one of them is on then 297 00:14:43,465 --> 00:14:44,335 one is shining 298 00:14:45,595 --> 00:14:47,035 and if the other one is on 299 00:14:47,395 --> 00:14:49,645 then the other one is shining and 300 00:14:49,645 --> 00:14:51,895 if both are on we have the 301 00:14:51,906 --> 00:14:55,405 three elegies blinking now the most important 302 00:14:55,405 --> 00:14:57,355 thing is just realizing that there are 303 00:14:57,355 --> 00:15:00,805 always four possibilities here low and low 304 00:15:01,405 --> 00:15:04,375 low and high high end low and 305 00:15:04,375 --> 00:15:05,695 high and high okay 306 00:15:05,695 --> 00:15:08,725 okay so check all four possibilities and 307 00:15:08,725 --> 00:15:10,735 make sure to compare them in the 308 00:15:10,735 --> 00:15:14,455 program with their behaviors okay so this 309 00:15:14,485 --> 00:15:16,705 is going to be your exercise for 310 00:15:16,705 --> 00:15:20,065 today with these two switches and four 311 00:15:20,125 --> 00:15:22,195 possibilities good luck