But in this lecture, I'll show you how to use pulse width modulation to control the intensity of the
light that comes out of infinity in this case, just like in the previous examples of conditionality
connected to Chipo 21.
Now, talking about the hardware, before we move on to the software side, just wanted to remind you
that on the E.S.P 32, you're looking here at the PIN layout chart.
Just zoom out for a second.
You can see that any Tapio with a tilt next to its pin is capable in this case.
For this example, I'm using Chip here you are 21, which is capable.
So as long as there is a tilde next to the pin that you want to use and it is free, it's not occupied
with something else, then you can apply and function to it.
All right, let's have a look at the script here, so I have created a little demonstration file called
Fadeout.
As you can see, it's on my computer file system.
I haven't copied it over to the three yet.
Having a quick look at it, I am going to be using, of course, repeatably m.
Module to control the ability and of course, the documentation being right here and also using a function
called range that comes with the Standard Micro Python and Python libraries and its documentation link.
Is this having a quick look at those two resources?
You can see that the W.M. functionality is part of the machine module and you can use this notation
to create a piece, an object.
You basically just call them.
Then you pass on the GPO that you want to use.
You can read or set the frequency of your M channel.
The default is 1000.
So if you don't set it and the default of 1000 is going to be used and then you can set its duty cycle
by calling the duty function and putting the duty cycle just a number between zero and one thousand
twenty three.
As you can see here, the documentation, if you don't pass a parameter in the function, then this
would return the current duty cycle.
So you can always check to see what it is before you change it.
It's another example here of how you can create a W object and set both its frequency and its duty cycle
in one in one function like that.
So I'm using the M functionality.
First of all up here, I'm just going with the default C, I'm just setting the pin to be a twenty one
and then down here in the infinite loop using the wild true loop, I've got a couple of loops.
The first one is counting up for the two to circle from zero to one thousand twenty three in step five
and then calling the duty cycle and setting the -- cycle according to what it is inside the loop.
And then the second that I'm counting down, that's within range function is useful.
I'm counting down from one thousand twenty three to zero in step, negative five minus five each time
going for a little sleep and then continuing with the loop.
So the built in function range looks like this.
It's got to overloaded functions.
The first one just has one parameter, the stop.
So if you go for range and then you give it a number, then it will count from zero up to that number
in step one.
The alternative is to go for this function here, which requires three parameters start to stop.
And then the step, which is the one that I'm using right here.
That makes it easy to count from a number to any other number using any step that you want.
All right.
So I'm going to upload this as a copy to the marketplace and device.
It's called his fate dot p y.
All right, and loaded into phony just to get rid of the one stored on the local filesystem, so don't
confuse it to this.
And I'm going to press the wrong button to get it to start.
And then you get the LDH on and off.
For the speed things up a little.
Which case I will need to interrupt.
Before I can make any changes to the sketch and then let's make that say 15 and minus 15 and save and
play again.
You can see that it now fades on and off faster, so you can either change the step parameter or reduce
or increase the sleep amount of time, and that will have an effect on the speed with which the on and
of.
All right.
That was easy enough.
Let's move on to the next lecture where I show you how to read the state of a button, and we do that
in a few variations, a few different ways by which you can read the state of the.