1 00:00:02,969 --> 00:00:05,430 hello in this exercise we are going 2 00:00:05,430 --> 00:00:07,020 to use the same circuit that we 3 00:00:07,020 --> 00:00:10,080 used in the previous exercise so you 4 00:00:10,080 --> 00:00:11,880 can see I have a voltage divider 5 00:00:11,940 --> 00:00:13,890 connected the same way we connected it 6 00:00:13,890 --> 00:00:16,350 the other day and we are reading 7 00:00:16,350 --> 00:00:19,500 from five volts to zero volts using 8 00:00:19,500 --> 00:00:20,100 the 9 00:00:20,160 --> 00:00:21,810 zero analog connector 10 00:00:23,070 --> 00:00:24,960 and we have the LED 11 00:00:26,190 --> 00:00:28,110 connected to the arduino board the usual 12 00:00:28,110 --> 00:00:28,470 way 13 00:00:29,700 --> 00:00:32,369 but there is something different instead of 14 00:00:32,369 --> 00:00:35,820 connecting it to number thirteen we are 15 00:00:35,820 --> 00:00:38,760 connecting it to number eleven you can 16 00:00:38,760 --> 00:00:40,440 see if i zoom in that numbers 17 00:00:40,440 --> 00:00:45,000 eleven ten nine six five and three 18 00:00:45,270 --> 00:00:46,620 they all have a line in front 19 00:00:46,620 --> 00:00:48,540 of their number it means that these 20 00:00:48,540 --> 00:00:49,680 connectors are different 21 00:00:49,680 --> 00:00:52,440 and so these numbers can provide digital 22 00:00:52,440 --> 00:00:54,120 values the same way we have been 23 00:00:54,120 --> 00:00:56,310 doing during the previous days with the 24 00:00:56,310 --> 00:00:59,190 high and low digital values but these 25 00:00:59,220 --> 00:01:01,770 six connectors the ones with the line 26 00:01:01,800 --> 00:01:04,200 in front of the numbers these can 27 00:01:04,200 --> 00:01:06,390 also provide analog values 28 00:01:08,190 --> 00:01:10,830 so this means that if we send 29 00:01:11,160 --> 00:01:14,400 one volts two volts three volts we 30 00:01:14,400 --> 00:01:16,140 could send one and a half two 31 00:01:16,140 --> 00:01:19,650 and a half two point four zero 32 00:01:19,650 --> 00:01:21,660 point three three point six whatever we 33 00:01:21,660 --> 00:01:24,690 want and if this LED is connected 34 00:01:24,690 --> 00:01:27,450 to eleven for instance it means that 35 00:01:27,450 --> 00:01:27,600 we 36 00:01:27,600 --> 00:01:30,120 we'll be able to provide any voltage 37 00:01:30,120 --> 00:01:32,430 amount we want to control the intensity 38 00:01:32,430 --> 00:01:34,890 of the LED so we will be 39 00:01:34,890 --> 00:01:36,750 able to decide if it will shine 40 00:01:36,810 --> 00:01:38,910 brighter or less bright 41 00:01:45,630 --> 00:01:46,860 so let's have a look at the 42 00:01:46,860 --> 00:01:49,500 simulation I will show you the code 43 00:01:49,500 --> 00:01:49,950 later 44 00:01:53,910 --> 00:01:56,190 if we're reading zero using the 45 00:01:56,190 --> 00:01:59,190 zero connector eleven doesn't change it doesn't 46 00:01:59,190 --> 00:02:01,230 send anything to the LED so it 47 00:02:01,230 --> 00:02:01,830 won't shine 48 00:02:05,850 --> 00:02:07,020 if we move it a little bit 49 00:02:07,020 --> 00:02:09,660 higher it means we're reading a number 50 00:02:09,660 --> 00:02:11,580 higher than zero and as you can 51 00:02:11,580 --> 00:02:13,980 see the LED is shining just a 52 00:02:13,980 --> 00:02:14,700 little bit more 53 00:02:15,840 --> 00:02:17,310 now if we move it more we 54 00:02:17,310 --> 00:02:19,710 read a number even higher the LED 55 00:02:19,710 --> 00:02:22,680 will shine brighter and the higher the 56 00:02:22,680 --> 00:02:24,390 number we read the brighter it will 57 00:02:24,390 --> 00:02:26,820 shine this is the brightest value on 58 00:02:26,820 --> 00:02:27,450 five 59 00:02:31,320 --> 00:02:33,210 so it's the brightest back to zero 60 00:02:33,210 --> 00:02:33,750 off 61 00:02:35,160 --> 00:02:36,660 back to five so you can see 62 00:02:36,660 --> 00:02:38,220 the range of values we're reading and 63 00:02:38,220 --> 00:02:39,390 sending to the LED 64 00:02:43,050 --> 00:02:44,580 now let's stop the simulation 65 00:02:47,160 --> 00:02:48,510 and before we have a look at 66 00:02:48,510 --> 00:02:50,400 the code we need to take into 67 00:02:50,400 --> 00:02:53,160 account that a zero although it reads 68 00:02:53,160 --> 00:02:56,100 analog values the arduino board will work 69 00:02:56,130 --> 00:03:00,030 using integral numbers do you remember that 70 00:03:00,030 --> 00:03:02,820 the analog input reads numbers from zero 71 00:03:02,820 --> 00:03:05,430 to one hundred and two we studied 72 00:03:05,430 --> 00:03:05,760 it in 73 00:03:05,790 --> 00:03:08,670 the previous exercise means that we're going 74 00:03:08,670 --> 00:03:11,820 to use one thousand twenty four values 75 00:03:13,260 --> 00:03:16,080 this number zero is related to zero 76 00:03:16,080 --> 00:03:19,380 volts and number twenty three number one 77 00:03:19,380 --> 00:03:21,870 thousand twenty three is related to five 78 00:03:21,870 --> 00:03:25,650 volts for instance if we have five 79 00:03:25,650 --> 00:03:28,080 thousand and twelve that one in the 80 00:03:28,080 --> 00:03:31,080 middle then we will be reading two 81 00:03:31,080 --> 00:03:32,430 and a half volts it's the value 82 00:03:32,430 --> 00:03:33,000 in the middle 83 00:03:39,420 --> 00:03:41,700 so there's a proportional relationship between the 84 00:03:41,700 --> 00:03:43,380 number we use and the voltage were 85 00:03:43,380 --> 00:03:45,660 reading when we use these numbers as 86 00:03:45,660 --> 00:03:47,580 output values we're going to use a 87 00:03:47,580 --> 00:03:50,010 lower range of values we're going to 88 00:03:50,010 --> 00:03:51,450 use a range of two hundred and 89 00:03:51,450 --> 00:03:54,300 fifty six we will use numbers from 90 00:03:54,300 --> 00:03:56,580 zero to two hundred and fifty five 91 00:03:57,180 --> 00:03:58,320 so zero is real 92 00:03:58,320 --> 00:04:00,420 rated to zero volts two hundred and 93 00:04:00,420 --> 00:04:02,880 fifty five is related to five volts 94 00:04:03,180 --> 00:04:04,890 and the one in the middle which 95 00:04:04,950 --> 00:04:07,140 would be a one hundred and twenty 96 00:04:07,140 --> 00:04:09,090 eight that is related to two and 97 00:04:09,090 --> 00:04:11,100 a half volts so you see that 98 00:04:11,100 --> 00:04:14,220 there's a proportional relationship between the integral 99 00:04:14,220 --> 00:04:15,960 number and the voltage 100 00:04:17,070 --> 00:04:19,290 so it's the same idea as the 101 00:04:19,380 --> 00:04:21,029 first one although the range is just 102 00:04:21,029 --> 00:04:22,260 four times shorter 103 00:04:23,520 --> 00:04:26,220 so how will we program it well 104 00:04:26,220 --> 00:04:27,390 the first thing we need to do 105 00:04:27,390 --> 00:04:29,790 is create a variable in this case 106 00:04:29,790 --> 00:04:33,180 our variable is called input and we 107 00:04:33,180 --> 00:04:35,550 read the analog input with this block 108 00:04:35,640 --> 00:04:37,410 the one that's connected to a zero 109 00:04:38,280 --> 00:04:39,900 and we store it in the variable 110 00:04:39,900 --> 00:04:40,770 called input 111 00:04:42,000 --> 00:04:43,590 and then we're going to divide this 112 00:04:43,590 --> 00:04:46,080 variable by four because the range we're 113 00:04:46,080 --> 00:04:48,930 using for this output is four times 114 00:04:48,930 --> 00:04:50,760 shorter than the range where using to 115 00:04:50,760 --> 00:04:53,850 read the values and we use this 116 00:04:53,850 --> 00:04:56,880 range to send this value to eleven 117 00:04:58,500 --> 00:05:00,810 so it will send the value to 118 00:05:00,810 --> 00:05:04,260 the LED and the LED shines according 119 00:05:04,260 --> 00:05:05,850 to the value that we're sending 120 00:05:09,090 --> 00:05:11,850 so on zero it doesn't shine here 121 00:05:11,850 --> 00:05:13,320 in the middle it shines a little 122 00:05:13,320 --> 00:05:15,660 bit and if we move it all 123 00:05:15,660 --> 00:05:16,170 the way 124 00:05:17,460 --> 00:05:20,040 it's the brightest okay so this is 125 00:05:20,040 --> 00:05:21,930 the circuit this is the first thing 126 00:05:21,930 --> 00:05:23,460 you have to do just create the 127 00:05:23,460 --> 00:05:25,770 circuit but this is just the first 128 00:05:25,770 --> 00:05:28,050 step your exercise is going to be 129 00:05:28,050 --> 00:05:28,740 a little different 130 00:05:30,150 --> 00:05:34,140 your exercise is here it's rgb we're 131 00:05:34,140 --> 00:05:36,450 going to use a new component that 132 00:05:36,450 --> 00:05:40,110 is called the rgb LED and you 133 00:05:40,110 --> 00:05:41,310 can find it down here in the 134 00:05:41,310 --> 00:05:42,390 components library 135 00:05:44,520 --> 00:05:46,170 so it's an LED with four 136 00:05:46,170 --> 00:05:48,960 pins four connectors the first one is 137 00:05:48,960 --> 00:05:51,750 called a red connector one of them 138 00:05:51,750 --> 00:05:53,820 is called the blue connector and one 139 00:05:53,820 --> 00:05:56,670 of them is the green connector and 140 00:05:56,670 --> 00:05:58,110 this one here is just the cathode 141 00:05:58,110 --> 00:05:59,760 and it's connected to the ground through 142 00:05:59,760 --> 00:06:02,280 the protection resistor that we always have 143 00:06:02,610 --> 00:06:03,600 at two hundred and twenty 144 00:06:03,948 --> 00:06:04,740 don't forget that 145 00:06:06,120 --> 00:06:08,070 so it means that this LED will 146 00:06:08,070 --> 00:06:11,820 combine three colors so we will read 147 00:06:11,850 --> 00:06:15,270 three different values using a zero a 148 00:06:15,270 --> 00:06:17,010 one and a two 149 00:06:19,470 --> 00:06:20,700 okay can you see that we have 150 00:06:20,700 --> 00:06:22,890 three voltage dividers connected the way we 151 00:06:22,890 --> 00:06:25,710 connected just one before we will use 152 00:06:25,710 --> 00:06:28,680 these three variables instead of having input 153 00:06:28,680 --> 00:06:31,830 we will have input one input to 154 00:06:31,920 --> 00:06:33,330 input three for example 155 00:06:36,930 --> 00:06:39,630 so we will be reading three values 156 00:06:39,810 --> 00:06:41,160 the same way that we have read 157 00:06:41,160 --> 00:06:43,530 them before and we will send three 158 00:06:43,530 --> 00:06:45,960 different analog outputs the same way we 159 00:06:45,960 --> 00:06:48,540 sent them before one for the red 160 00:06:48,900 --> 00:06:50,370 one for the blue and one for 161 00:06:50,370 --> 00:06:50,730 the green 162 00:06:51,930 --> 00:06:54,120 so let's look at the simulation to 163 00:06:54,120 --> 00:06:56,460 understand it better if i move this 164 00:06:56,460 --> 00:06:58,770 first one the red control it means 165 00:06:58,770 --> 00:07:00,660 I'm sending five volts through the red 166 00:07:00,660 --> 00:07:01,260 wires 167 00:07:03,120 --> 00:07:04,260 and you can see the LED is 168 00:07:04,260 --> 00:07:06,900 red if i use the second one 169 00:07:07,080 --> 00:07:09,120 to the maximum value now I'm sending 170 00:07:09,120 --> 00:07:10,980 five volts to the blue wire 171 00:07:13,560 --> 00:07:14,790 and it's the same with the last 172 00:07:14,790 --> 00:07:16,620 one now I am going to send 173 00:07:16,620 --> 00:07:18,690 five volts through the green wire 174 00:07:21,270 --> 00:07:22,560 so the important thing is that we 175 00:07:22,560 --> 00:07:25,770 can combine for example green and blue 176 00:07:26,100 --> 00:07:27,660 and we'll get a new color it's 177 00:07:27,660 --> 00:07:29,130 almost turquoise 178 00:07:30,720 --> 00:07:32,640 what happens if we combine blue and 179 00:07:32,640 --> 00:07:33,030 red 180 00:07:35,610 --> 00:07:37,260 well you know we'll have purple 181 00:07:38,460 --> 00:07:40,050 so the idea is that every color 182 00:07:40,050 --> 00:07:42,720 can be produced using some combination of 183 00:07:42,720 --> 00:07:45,300 red green and blue and I'm not 184 00:07:45,300 --> 00:07:46,740 going to show you the code but 185 00:07:46,740 --> 00:07:49,350 it will be something that's repeated three 186 00:07:49,350 --> 00:07:51,150 times like the goal of the previous 187 00:07:51,150 --> 00:07:53,340 exercise so you have to use a 188 00:07:53,340 --> 00:07:56,520 variable read a number from the connectors 189 00:07:56,610 --> 00:07:58,560 a zero a one and a 190 00:07:58,560 --> 00:08:00,780 a two and storing the number in 191 00:08:00,780 --> 00:08:03,570 the variable then dividing the variable by 192 00:08:03,570 --> 00:08:05,490 four and sending it to the output 193 00:08:05,490 --> 00:08:09,660 we want eleven ten and nine if 194 00:08:09,660 --> 00:08:11,160 you know the connections for this one 195 00:08:11,160 --> 00:08:13,200 and the exercise should be pretty simple 196 00:08:13,230 --> 00:08:16,470 so try controlling the rgb LED using 197 00:08:16,470 --> 00:08:18,030 three voltage dividers 198 00:08:19,170 --> 00:08:19,650 good luck