1
00:00:00,660 --> 00:00:07,200
But in this lecture, I'll show you how to use pulse width modulation to control the intensity of the

2
00:00:07,200 --> 00:00:12,830
light that comes out of infinity in this case, just like in the previous examples of conditionality

3
00:00:12,870 --> 00:00:15,450
connected to Chipo 21.

4
00:00:15,960 --> 00:00:21,240
Now, talking about the hardware, before we move on to the software side, just wanted to remind you

5
00:00:21,240 --> 00:00:29,490
that on the E.S.P 32, you're looking here at the PIN layout chart.

6
00:00:29,520 --> 00:00:31,890
Just zoom out for a second.

7
00:00:32,220 --> 00:00:41,040
You can see that any Tapio with a tilt next to its pin is capable in this case.

8
00:00:41,040 --> 00:00:46,430
For this example, I'm using Chip here you are 21, which is capable.

9
00:00:46,710 --> 00:00:52,890
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

10
00:00:52,890 --> 00:00:56,940
with something else, then you can apply and function to it.

11
00:00:57,890 --> 00:01:07,640
All right, let's have a look at the script here, so I have created a little demonstration file called

12
00:01:07,640 --> 00:01:08,720
Fadeout.

13
00:01:09,260 --> 00:01:12,350
As you can see, it's on my computer file system.

14
00:01:12,350 --> 00:01:14,900
I haven't copied it over to the three yet.

15
00:01:15,290 --> 00:01:20,690
Having a quick look at it, I am going to be using, of course, repeatably m.

16
00:01:21,730 --> 00:01:29,770
Module to control the ability and of course, the documentation being right here and also using a function

17
00:01:29,770 --> 00:01:39,610
called range that comes with the Standard Micro Python and Python libraries and its documentation link.

18
00:01:39,610 --> 00:01:44,770
Is this having a quick look at those two resources?

19
00:01:44,800 --> 00:01:54,670
You can see that the W.M. functionality is part of the machine module and you can use this notation

20
00:01:54,670 --> 00:01:56,800
to create a piece, an object.

21
00:01:56,810 --> 00:01:58,920
You basically just call them.

22
00:01:59,260 --> 00:02:02,400
Then you pass on the GPO that you want to use.

23
00:02:02,890 --> 00:02:08,890
You can read or set the frequency of your M channel.

24
00:02:09,340 --> 00:02:11,160
The default is 1000.

25
00:02:11,170 --> 00:02:18,880
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

26
00:02:19,420 --> 00:02:27,160
by calling the duty function and putting the duty cycle just a number between zero and one thousand

27
00:02:27,160 --> 00:02:27,880
twenty three.

28
00:02:28,240 --> 00:02:34,780
As you can see here, the documentation, if you don't pass a parameter in the function, then this

29
00:02:34,780 --> 00:02:37,840
would return the current duty cycle.

30
00:02:37,850 --> 00:02:41,200
So you can always check to see what it is before you change it.

31
00:02:41,860 --> 00:02:51,460
It's another example here of how you can create a W object and set both its frequency and its duty cycle

32
00:02:51,460 --> 00:02:54,070
in one in one function like that.

33
00:02:55,000 --> 00:02:58,060
So I'm using the M functionality.

34
00:02:58,300 --> 00:03:06,850
First of all up here, I'm just going with the default C, I'm just setting the pin to be a twenty one

35
00:03:07,090 --> 00:03:14,140
and then down here in the infinite loop using the wild true loop, I've got a couple of loops.

36
00:03:14,230 --> 00:03:21,790
The first one is counting up for the two to circle from zero to one thousand twenty three in step five

37
00:03:21,790 --> 00:03:27,820
and then calling the duty cycle and setting the -- cycle according to what it is inside the loop.

38
00:03:28,030 --> 00:03:32,980
And then the second that I'm counting down, that's within range function is useful.

39
00:03:33,250 --> 00:03:41,020
I'm counting down from one thousand twenty three to zero in step, negative five minus five each time

40
00:03:41,230 --> 00:03:44,890
going for a little sleep and then continuing with the loop.

41
00:03:45,250 --> 00:03:49,720
So the built in function range looks like this.

42
00:03:50,270 --> 00:03:52,840
It's got to overloaded functions.

43
00:03:52,840 --> 00:03:55,290
The first one just has one parameter, the stop.

44
00:03:55,300 --> 00:04:01,810
So if you go for range and then you give it a number, then it will count from zero up to that number

45
00:04:01,810 --> 00:04:02,800
in step one.

46
00:04:03,370 --> 00:04:09,340
The alternative is to go for this function here, which requires three parameters start to stop.

47
00:04:09,340 --> 00:04:14,380
And then the step, which is the one that I'm using right here.

48
00:04:15,310 --> 00:04:20,560
That makes it easy to count from a number to any other number using any step that you want.

49
00:04:21,340 --> 00:04:21,760
All right.

50
00:04:21,770 --> 00:04:27,850
So I'm going to upload this as a copy to the marketplace and device.

51
00:04:27,940 --> 00:04:31,570
It's called his fate dot p y.

52
00:04:33,860 --> 00:04:42,630
All right, and loaded into phony just to get rid of the one stored on the local filesystem, so don't

53
00:04:42,650 --> 00:04:43,790
confuse it to this.

54
00:04:44,960 --> 00:04:51,980
And I'm going to press the wrong button to get it to start.

55
00:04:52,820 --> 00:04:56,180
And then you get the LDH on and off.

56
00:04:57,650 --> 00:04:59,330
For the speed things up a little.

57
00:05:01,480 --> 00:05:03,510
Which case I will need to interrupt.

58
00:05:05,350 --> 00:05:14,540
Before I can make any changes to the sketch and then let's make that say 15 and minus 15 and save and

59
00:05:14,620 --> 00:05:15,360
play again.

60
00:05:16,990 --> 00:05:28,450
You can see that it now fades on and off faster, so you can either change the step parameter or reduce

61
00:05:28,450 --> 00:05:36,790
or increase the sleep amount of time, and that will have an effect on the speed with which the on and

62
00:05:36,820 --> 00:05:37,180
of.

63
00:05:38,670 --> 00:05:39,080
All right.

64
00:05:39,150 --> 00:05:40,560
That was easy enough.

65
00:05:40,680 --> 00:05:47,490
Let's move on to the next lecture where I show you how to read the state of a button, and we do that

66
00:05:47,640 --> 00:05:53,220
in a few variations, a few different ways by which you can read the state of the.
