Hello and welcome.
In this lesson, we are going to take on the P.W. ambitions of the sport.
All 36 of the 32 general purpose Input-Output Benz has a P.W. arm capability.
This is a really great thing.
But we must use more complex code to reach the same result on other pins.
So let's put it on one of the general purpose, Input-Output with appreciable output signal.
Now if you went to this schematic all this pin out for these people, you can see that all of these
pins can be used to generate P.W. arm signals.
The first thing that you need to think about when programming a P.W. on the signal is its frequency.
You need to retrieve that signal at a certain or a specific frequency.
We would use a value of 5000 hertz.
That works fine with our lead.
We must also specify that it P.W. Omni channel and the resolution of the BW and duty cycle I want.
Explain that BWR, because you must have some basic knowledge about BW signals, but what it takes is
a resolution, a channel and a frequency.
So after specifying that you cycle using the resolution and the frequency on the channel, we can start
programming.
We can choose a channel from zero to 15 and a resolution between one and 16 bits.
We will use Channel zero and the resolution of eight bits.
So let's get started.
That's good, according to your thumbnail sketch.
And here's another sketch.
Let's define some variables.
First, we need to define that frequency and frequency.
And let's make it 5000.
Then we need the left channel.
Let's make it zero and we need the resolution.
And let's make it eight.
Now let's use the general purpose input output one.
Number two where we have our lead on our external LED, 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 hide this code.
Now what we are going to write in inside the setup function won't be something we are used to while
going to light.
Let's see a dustbin and lid see setup.
Now the Let's See attachment and let's use it up.
There are basically functions for the BW arm configuration.
They are very similar to another great functional Arduino.
So now that USP.
Doesn't support another great function, but it does support a much better one, which is the one that
we already mentioned.
Let's see right there.
Let's see.
Light function is very similar to an outlook, right?
It also requires two parameters that BW channel that we want to write about Utah and the BW value.
We want to write to the selected channel.
Now, let's first finish the setup function.
Now the let's see setup function.
Will take three parameters.
The first one will be valid channel.
The second one will be the frequency.
The third one will be the resolution, which we already defined up there.
Next, we are going to assign a lead to that channel, so let see a dash pin.
Now the lid pin we already chose is two and we want to attach it to the lid channel that we have chosen.
This is it.
This is how you finish sitting that BW, um, frequency resolution and channel and how you can attach
it to any output pin.
Now, to tear down the lid, which is connected to PIN number two using the lid channel output from
the BW, I'm signal.
We need to set a specific brightness now to turn it on or off.
We must define the duty cycle.
For example, the turn of the lid that each cycle must be zero on the function lid see right that we
already mentioned can be used inside the loop 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 analog, 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 add zero.
This will turn off valid because we have since zero.
To the left channel, which has been number two, and it will set the protest to zero.
Now different values of the duty cycle.
Will turn on the lead with different priorities.
Now this variable can be from zero up to 255 once that resolution used is eight bits.
If we used 18 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 the choice is yours, but you need to make sure that you are choosing a duty cycle that matches your
resolution.
So an eight bit resolution, that cycle would be between zero and 125 to 155.
OK, now that we are done with this, we can use that potential meter connected to the analog pen from
the previous lesson to control the brightness of that lid, or we can simply send values.
Now, to test this out, let's complete the code.
Let's first and the setup menu add cereal to begin and choose a moderate one hundred fifteen thousand
two hundred, then other 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 name this thing on.
OK, now we have the lid setup on the lid see at dustbin and we can use the lid 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't send.
Duty cycle, let's define duty cycle here.
Plus.
Equal +1, and let's add.
It's make it 15 milliseconds, okay, now, uh, let's walk this line down here.
It will start with zero.
Then it will be +1 or let's make +10 and we'll keep moving until it reaches 235.
We kind of had an if statement, but this this this called out.
Let's first upload or verify it to make sure it doesn't have any errors.
Let's save it.
BW on this thing.
OK, then combining now, let's upload the code.
We should we should add a line to make sure that we will pretend that it's cycle.
We want to combine the cold, but for now.
Let's put it, compile it so that we can get that just like in here now.
Let's recompile the code for the fight again.
Now it's loaded.
OK, now.
As you can see, it went above to 155 very fast, so we need to control this once the duty cycle reaches
its cycle is of equal to 125.
We needed to reset to zero.
Now let's combine it again.
Now, let's upload it.
OK.
Done.
Now, as you can see, once it reaches 255 intercepts to zero and from your ISP board, you can see
that the built in led all of accelerate that you are connecting is fading in and out using this very
simple chord.
Now, now let's summarize what we did this last one.
We have saved the frequency to five thousand.
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 duty cycle of zero and he shell out of the theater communication.
Here we used new functions.
Let's use it up to set up the BW frequency channel and resolution.
And this lets you attach pin to attach the function to us to a specific pin, which has been number
two here.
And the LCD right is basically like analog, right?
It takes a channel and the duty cycle and to try its value to that channel.
Now in this photo, we have used the LED channel, which was proudly attached here to pick number two
and the new Typekit.
And we kept increasing the cycle by 10.
And printed on the Tehran monitor.
Now, once that U.S.A. reaches 255, which is the limit here, we did that.
I said the cycle to zero.
To repeat the process again.
And that is how you can fade added using P.W. Signal.
You can apply this to any other thing.
You can choose 10 bit resolution in that case, if you did choose 10 bit resolution.
You will get values between zero and one thousand twenty three.
So in that case, this if statement will be 1023 instead of a set of 255.
That's it.
I know that this was a long glass on, but I wanted to explain, Uh, I'm using an example.
I hope that everything is now well explained to you.
If you have any question regarding anything, you can ask.
This is Ashraf.
See you next lesson.
Happy ending.
This is educational engineering team.