1 00:00:00,750 --> 00:00:01,680 Hello and welcome. 2 00:00:03,240 --> 00:00:12,450 In this lesson, we are going to take on the PWI campaigns of the E.S.P board, all 36 of the E.S.P 3 00:00:12,450 --> 00:00:18,060 32 general-purpose input output, Penns has a capability. 4 00:00:19,220 --> 00:00:20,780 This is a really great thing. 5 00:00:21,840 --> 00:00:27,600 But we must use more complex code to reach the same result on other pens. 6 00:00:29,270 --> 00:00:35,870 So let's program one of the general purpose and output with an output signal. 7 00:00:36,710 --> 00:00:46,160 Now, if you want to this schematic, all this pan out for various people, you can see that all of 8 00:00:46,160 --> 00:00:50,450 these pins can be used to generate PWI and signals. 9 00:00:51,320 --> 00:00:59,550 The first thing that you need to think about when programming a signal is its frequency. 10 00:01:00,110 --> 00:01:04,420 You need to generate that signal at a certain or a specific frequency. 11 00:01:04,940 --> 00:01:10,860 We will use a value of 5000 hertz that works fine with our lit. 12 00:01:11,480 --> 00:01:18,810 We must also specify that PWI channel and the resolution of the duty cycle. 13 00:01:19,760 --> 00:01:20,570 I want. 14 00:01:21,690 --> 00:01:28,500 Explain that one, because you must have some basic knowledge about bwl signals, but what it takes 15 00:01:28,500 --> 00:01:32,970 is a resolution, a channel and a frequency. 16 00:01:33,720 --> 00:01:42,390 So after specifying that duty cycle, using that resolution and the frequency and the channel, we can 17 00:01:42,390 --> 00:01:49,680 start programming, we can choose a channel from zero to 15 and a resolution between one and sixteen 18 00:01:49,680 --> 00:01:50,070 bits. 19 00:01:50,790 --> 00:01:54,970 We will use a Channel zero and a resolution of eight bits. 20 00:01:55,350 --> 00:01:57,670 So let's get started. 21 00:01:57,760 --> 00:01:58,200 That's good. 22 00:01:58,230 --> 00:02:00,290 According to a new sketch. 23 00:02:01,470 --> 00:02:03,320 And here's a new sketch. 24 00:02:03,330 --> 00:02:05,330 Let's define some variables. 25 00:02:05,670 --> 00:02:12,690 First, we need to define the frequency and frequency and let's make it 5000. 26 00:02:14,580 --> 00:02:16,130 Then we need little channel. 27 00:02:18,660 --> 00:02:20,340 Let's make it zero. 28 00:02:21,480 --> 00:02:23,190 And we need that resolution. 29 00:02:25,980 --> 00:02:27,870 And let's make it eight. 30 00:02:29,120 --> 00:02:37,500 Now let's use the general purpose, input output will number two, where we have our lead or our externally 31 00:02:37,620 --> 00:02:38,880 connected or attached. 32 00:02:39,070 --> 00:02:42,140 It's it also has a built in lid that can be used. 33 00:02:42,690 --> 00:02:49,110 So these parameters must be defined inside the setup function. 34 00:02:49,410 --> 00:02:50,670 So let's go. 35 00:02:50,670 --> 00:02:52,650 And why this code? 36 00:02:53,620 --> 00:03:00,800 Now, what we are going to inside the setup function won't be something we are used to. 37 00:03:01,200 --> 00:03:05,830 We are going to let's see Atash PIN and Lizzi set up. 38 00:03:06,480 --> 00:03:09,600 Now the Lizzi Atash pin and let's use it up. 39 00:03:09,610 --> 00:03:14,100 There are basically functions for the arm configuration. 40 00:03:14,520 --> 00:03:18,090 They are very similar to analog right function on Arduino. 41 00:03:18,900 --> 00:03:21,870 So now they aspy. 42 00:03:22,940 --> 00:03:29,270 Doesn't support an underground function, but it does support a much better one, which is the one that 43 00:03:29,270 --> 00:03:30,290 you already mentioned. 44 00:03:30,560 --> 00:03:32,750 Let's see right then. 45 00:03:32,750 --> 00:03:33,070 Let's see. 46 00:03:33,080 --> 00:03:35,810 Like function is very similar to analog, right. 47 00:03:35,840 --> 00:03:43,520 It also requires two parameters that and channel that we want to write a value to. 48 00:03:43,910 --> 00:03:45,410 And that bwl value. 49 00:03:45,430 --> 00:03:48,350 We want to write to the selected channel. 50 00:03:49,310 --> 00:03:57,080 Now, let's first finish the setup function, now the let's see setup function. 51 00:04:00,520 --> 00:04:04,000 We'll take three parameters, the first one will be the lead channel. 52 00:04:07,100 --> 00:04:10,370 The second one will be the frequency. 53 00:04:10,880 --> 00:04:14,860 The third one will be the resolution, which we already find up there. 54 00:04:19,790 --> 00:04:22,470 Next, we are going to assign a link to that channel. 55 00:04:22,490 --> 00:04:37,730 So let's see Atash Penn now the lead Penn we already choose is to and we want to attach it to that channel 56 00:04:37,730 --> 00:04:38,930 that we have chosen. 57 00:04:40,730 --> 00:04:41,420 This is it. 58 00:04:41,430 --> 00:04:49,850 This is how you finish setting up that BW, um, frequency resolution and channel and how you can attach 59 00:04:49,850 --> 00:04:52,040 it to any output pin. 60 00:04:53,940 --> 00:05:02,250 Now to turn on the lid, which is connected to PIN number two, using the Red Channel outward from the 61 00:05:02,250 --> 00:05:10,200 BW um, signal, we need to set a specific brightness now to turn the light on or off. 62 00:05:10,240 --> 00:05:16,890 We must define that duty cycle, for example, turn of the lid that each cycle must be zero and the 63 00:05:16,890 --> 00:05:25,710 function lid see right that we already mentioned can be used inside the room to set the brightness to 64 00:05:25,710 --> 00:05:26,050 zero. 65 00:05:26,460 --> 00:05:27,000 Now. 66 00:05:28,780 --> 00:05:30,970 We can use that function right now. 67 00:05:31,000 --> 00:05:31,930 That's right, let's see. 68 00:05:32,540 --> 00:05:32,880 Right. 69 00:05:35,110 --> 00:05:37,290 It's exactly like analogue, right? 70 00:05:37,300 --> 00:05:38,920 And it takes two parameters. 71 00:05:38,920 --> 00:05:47,770 The first one is the lead channel, which is this variable, and the second one is the duty cycle. 72 00:05:49,810 --> 00:05:55,360 Now, you can add in duty cycle here. 73 00:05:55,750 --> 00:06:01,660 And at zero, this will turn off valid because we have since zero. 74 00:06:02,790 --> 00:06:11,100 To the lead channel, which has been number two, and it will set the protest to zero now different 75 00:06:11,100 --> 00:06:12,510 values of the news cycle. 76 00:06:13,650 --> 00:06:22,980 We'll turn on the lead with different priorities now, this variable can be from zero up to 255 once 77 00:06:23,100 --> 00:06:25,710 the resolution used is eight bits. 78 00:06:26,190 --> 00:06:35,480 If we used a 10 bit resolution, it can go from zero up to 1024 or 1023 and so on. 79 00:06:35,700 --> 00:06:42,060 We already mentioned that you can choose a resolution between one and up to 16. 80 00:06:42,780 --> 00:06:44,850 So that choice is yours. 81 00:06:44,850 --> 00:06:51,040 But you need to make sure that you are choosing a cycle that matches your resolution. 82 00:06:52,050 --> 00:06:58,980 So in a better solution, that cycle will be between zero and 225 255. 83 00:06:59,550 --> 00:07:05,380 OK, now that we are done with this, we can use that potential. 84 00:07:05,400 --> 00:07:15,000 We connected to the analog pin from the previous lesson to control the brightness of that lead. 85 00:07:15,000 --> 00:07:19,760 Or we can simply send values now to test this out. 86 00:07:20,370 --> 00:07:21,750 Let's complete the code. 87 00:07:22,550 --> 00:07:25,770 Let us first and the setup menu. 88 00:07:26,190 --> 00:07:39,030 Add serial dowbiggin and choose a moderate one hundred fifteen thousand two hundred, then add odelay 89 00:07:39,030 --> 00:07:43,320 delay as usual for one second 90 00:07:45,990 --> 00:07:46,980 after the delay. 91 00:07:47,130 --> 00:07:51,600 Let's write a sentence to make sure that everything is working correctly. 92 00:07:52,020 --> 00:08:03,870 Trend line and let's limit this thing readable are OK. 93 00:08:03,960 --> 00:08:11,960 Now we have a valid set up and the C Atash pen and we can use that. 94 00:08:12,000 --> 00:08:15,240 Let's see right up here. 95 00:08:16,830 --> 00:08:23,390 And the first value that will be written is zero so that it will be off now inside the void loop. 96 00:08:23,430 --> 00:08:28,560 We can send other values we can send. 97 00:08:30,810 --> 00:08:31,870 Duty cycle. 98 00:08:31,910 --> 00:08:36,380 Let's define this cycle here plus. 99 00:08:38,610 --> 00:08:41,970 Equal plus one and let's add odelay. 100 00:08:47,690 --> 00:08:49,790 Let's make it 15 milliseconds. 101 00:08:50,780 --> 00:09:02,390 OK, now let's move this line down here, it will start with zero, then it will be plus one or let's 102 00:09:02,390 --> 00:09:08,930 make it blastin and it will keep moving until it reaches 255. 103 00:09:08,930 --> 00:09:12,890 We can add and if statement Bartletts this this called out. 104 00:09:15,910 --> 00:09:20,110 Let's first upload the code or verify it to make sure it doesn't have any errors. 105 00:09:21,220 --> 00:09:22,270 Let's save it. 106 00:09:25,360 --> 00:09:27,160 BW on this thing. 107 00:09:38,680 --> 00:09:41,170 OK, Duncan, comparing now let's upload the code. 108 00:09:47,760 --> 00:09:54,270 So we should we should underline to make sure that we will prevent that cycle. 109 00:10:02,200 --> 00:10:05,050 We want to combine the cold, but for now. 110 00:10:11,700 --> 00:10:17,180 Let's put it so that we can get that cycle here now. 111 00:10:18,640 --> 00:10:22,410 Let's recompile the code for the fight again. 112 00:10:30,830 --> 00:10:32,030 Now, let's it. 113 00:11:13,280 --> 00:11:14,330 OK, now. 114 00:11:15,370 --> 00:11:21,220 As you can see, it went above to 155 very fast, so we need to control this. 115 00:11:21,670 --> 00:11:30,130 Once that cycle reaches, its cycle is over equal to 125. 116 00:11:30,730 --> 00:11:33,960 We needed to reset to zero. 117 00:11:36,530 --> 00:11:38,300 Now, let's call it again. 118 00:11:40,810 --> 00:11:41,980 Now, let's upload it. 119 00:12:00,270 --> 00:12:11,850 OK, Don, now, as you can see, once it reaches 255, it resets to zero, and from your E.S.P ball, 120 00:12:11,860 --> 00:12:19,380 you can see that apelt and let all accelerate that you are connecting is fading in and out using this 121 00:12:19,680 --> 00:12:22,390 very simple code now. 122 00:12:23,650 --> 00:12:26,130 Now, let's summarize what we did. 123 00:12:26,260 --> 00:12:27,000 This lesson. 124 00:12:27,150 --> 00:12:29,870 We have set the frequency to 5000. 125 00:12:30,360 --> 00:12:36,900 We have choose the channel to be zero and we have chosen the resolution to be eight, which means that 126 00:12:36,900 --> 00:12:39,980 we have to cycle between zero and 255. 127 00:12:40,800 --> 00:12:46,710 We started with a cycle of zero and eventually the zero communication here. 128 00:12:46,710 --> 00:12:48,240 We used new functions. 129 00:12:48,240 --> 00:12:54,570 Let's use set up to set up that B.W. frequency channel and resolution. 130 00:12:54,990 --> 00:13:03,480 And this Lizzi Atash been to attach that one function to us and to a specific pin, which has been number 131 00:13:03,480 --> 00:13:04,020 two here. 132 00:13:05,700 --> 00:13:08,200 And the LCD right is basically like analogue. 133 00:13:08,200 --> 00:13:08,600 Right. 134 00:13:08,610 --> 00:13:15,540 It takes a channel and that you cycle and the it's a value to that channel. 135 00:13:16,780 --> 00:13:24,430 Now, in this fight, Lou, we have used the lead channel, which was already attached here to be number 136 00:13:24,430 --> 00:13:29,350 two, and that would cycle and we kept increasing the cycle by 10. 137 00:13:30,750 --> 00:13:32,590 And printed on the Tehran monitor. 138 00:13:33,060 --> 00:13:41,910 Now, once that music reaches 255, which is the limit here, we did the say that cycle to zero to repeat 139 00:13:41,910 --> 00:13:42,890 the process again. 140 00:13:43,920 --> 00:13:49,930 And that is how you can fit and using PWI signal. 141 00:13:50,010 --> 00:13:52,020 You can apply this to any other thing. 142 00:13:52,560 --> 00:13:54,830 You can choose better resolution. 143 00:13:55,390 --> 00:14:04,710 In that case, if you choose 10 better resolution, you will get values between zero and one thousand 144 00:14:06,300 --> 00:14:06,960 twenty three. 145 00:14:07,320 --> 00:14:14,300 So in that case, this statement will be one thousand twenty three instead of a set of 255. 146 00:14:15,100 --> 00:14:18,930 That said, I know that this was a long classen, but I wanted to explain. 147 00:14:21,600 --> 00:14:23,160 I'm using an example. 148 00:14:23,380 --> 00:14:27,720 I hope that everything is now well explained to you. 149 00:14:27,720 --> 00:14:30,730 If you have any questions regarding anything you can ask. 150 00:14:30,750 --> 00:14:31,590 This is Ashraf. 151 00:14:32,220 --> 00:14:34,020 So your next lesson, happy learning. 152 00:14:35,910 --> 00:14:37,830 This is educational engineering team.