Hello and welcome.
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
32 general-purpose input output, Penns has a capability.
This is a really great thing.
But we must use more complex code to reach the same result on other pens.
So let's program one of the general purpose and output with an output signal.
Now, if you want to this schematic, all this pan out for various people, you can see that all of
these pins can be used to generate PWI and signals.
The first thing that you need to think about when programming a signal is its frequency.
You need to generate that signal at a certain or a specific frequency.
We will use a value of 5000 hertz that works fine with our lit.
We must also specify that PWI channel and the resolution of the duty cycle.
I want.
Explain that one, because you must have some basic knowledge about bwl signals, but what it takes
is a resolution, a channel and a frequency.
So after specifying that duty cycle, using that resolution and the frequency and the channel, we can
start programming, we can choose a channel from zero to 15 and a resolution between one and sixteen
bits.
We will use a Channel zero and a resolution of eight bits.
So let's get started.
That's good.
According to a new sketch.
And here's a new sketch.
Let's define some variables.
First, we need to define the frequency and frequency and let's make it 5000.
Then we need little channel.
Let's make it zero.
And we need that resolution.
And let's make it eight.
Now let's use the general purpose, input output will number two, where we have our lead or our externally
connected or attached.
It's it also has a built in lid that can be used.
So these parameters must be defined inside the setup function.
So let's go.
And why this code?
Now, what we are going to inside the setup function won't be something we are used to.
We are going to let's see Atash PIN and Lizzi set up.
Now the Lizzi Atash pin and let's use it up.
There are basically functions for the arm configuration.
They are very similar to analog right function on Arduino.
So now they aspy.
Doesn't support an underground function, but it does support a much better one, which is the one that
you already mentioned.
Let's see right then.
Let's see.
Like function is very similar to analog, right.
It also requires two parameters that and channel that we want to write a value to.
And that bwl value.
We want to write to the selected channel.
Now, let's first finish the setup function, now the let's see setup function.
We'll take three parameters, the first one will be the lead channel.
The second one will be the frequency.
The third one will be the resolution, which we already find up there.
Next, we are going to assign a link to that channel.
So let's see Atash Penn now the lead Penn we already choose is to and we want to attach it to that channel
that we have chosen.
This is it.
This is how you finish setting up that BW, um, frequency resolution and channel and how you can attach
it to any output pin.
Now to turn on the lid, which is connected to PIN number two, using the Red Channel outward from the
BW um, signal, we need to set a specific brightness now to turn the light on or off.
We must define that duty cycle, for example, turn of the lid that each cycle must be zero and the
function lid see right that we already mentioned can be used inside the room to set the brightness to
zero.
Now.
We can use that function right now.
That's right, let's see.
Right.
It's exactly like analogue, right?
And it takes two parameters.
The first one is the lead channel, which is this variable, and the second one is the duty cycle.
Now, you can add in duty cycle here.
And at zero, this will turn off valid because we have since zero.
To the lead channel, which has been number two, and it will set the protest to zero now different
values of the news cycle.
We'll turn on the lead with different priorities now, this variable can be from zero up to 255 once
the resolution used is eight bits.
If we used a 10 bit resolution, it can go from zero up to 1024 or 1023 and so on.
We already mentioned that you can choose a resolution between one and up to 16.
So that choice is yours.
But you need to make sure that you are choosing a cycle that matches your resolution.
So in a better solution, that cycle will be between zero and 225 255.
OK, now that we are done with this, we can use that potential.
We connected to the analog pin from the previous lesson to control the brightness of that lead.
Or we can simply send values now to test this out.
Let's complete the code.
Let us first and the setup menu.
Add serial dowbiggin and choose a moderate one hundred fifteen thousand two hundred, then add odelay
delay as usual for one second
after the delay.
Let's write a sentence to make sure that everything is working correctly.
Trend line and let's limit this thing readable are OK.
Now we have a valid set up and the C Atash pen and we can use that.
Let's see right up here.
And the first value that will be written is zero so that it will be off now inside the void loop.
We can send other values we can send.
Duty cycle.
Let's define this cycle here plus.
Equal plus one and let's add odelay.
Let's make it 15 milliseconds.
OK, now let's move this line down here, it will start with zero, then it will be plus one or let's
make it blastin and it will keep moving until it reaches 255.
We can add and if statement Bartletts this this called out.
Let's first upload the code or verify it to make sure it doesn't have any errors.
Let's save it.
BW on this thing.
OK, Duncan, comparing now let's upload the code.
So we should we should underline to make sure that we will prevent that cycle.
We want to combine the cold, but for now.
Let's put it so that we can get that cycle here now.
Let's recompile the code for the fight again.
Now, let's it.
OK, now.
As you can see, it went above to 155 very fast, so we need to control this.
Once that cycle reaches, its cycle is over equal to 125.
We needed to reset to zero.
Now, let's call it again.
Now, let's upload it.
OK, Don, now, as you can see, once it reaches 255, it resets to zero, and from your E.S.P ball,
you can see that apelt and let all accelerate that you are connecting is fading in and out using this
very simple code now.
Now, let's summarize what we did.
This lesson.
We have set the frequency to 5000.
We have choose the channel to be zero and we have chosen the resolution to be eight, which means that
we have to cycle between zero and 255.
We started with a cycle of zero and eventually the zero communication here.
We used new functions.
Let's use set up to set up that B.W. frequency channel and resolution.
And this Lizzi Atash been to attach that one function to us and to a specific pin, which has been number
two here.
And the LCD right is basically like analogue.
Right.
It takes a channel and that you cycle and the it's a value to that channel.
Now, in this fight, Lou, we have used the lead channel, which was already attached here to be number
two, and that would cycle and we kept increasing the cycle by 10.
And printed on the Tehran monitor.
Now, once that music reaches 255, which is the limit here, we did the say that cycle to zero to repeat
the process again.
And that is how you can fit and using PWI signal.
You can apply this to any other thing.
You can choose better resolution.
In that case, if you choose 10 better resolution, you will get values between zero and one thousand
twenty three.
So in that case, this statement will be one thousand twenty three instead of a set of 255.
That said, I know that this was a long classen, but I wanted to explain.
I'm using an example.
I hope that everything is now well explained to you.
If you have any questions regarding anything you can ask.
This is Ashraf.
So your next lesson, happy learning.
This is educational engineering team.