1
00:00:00,690 --> 00:00:05,620
Hi and welcome to a new section in this course in this lecture.

2
00:00:05,640 --> 00:00:12,000
I'm going to talk about timers, in particular the hardware timers that are available to you via Micro

3
00:00:12,010 --> 00:00:19,050
Python, and they are implemented in hardware in the E.S.P 32 later in this section.

4
00:00:19,050 --> 00:00:25,590
And what we're going to talk about other capabilities that are embedded in the HP 32 and you can use

5
00:00:25,590 --> 00:00:31,680
them through micro python, such as, for example, the ability to control the C.P.U clock of your E.S.P

6
00:00:31,680 --> 00:00:40,560
32 to access the integrated whole effect sensor and the raw temperature sensor that gives you information

7
00:00:40,560 --> 00:00:42,050
about how hot your is.

8
00:00:42,090 --> 00:00:50,460
B 32 is running how to put your ESB 32 into deep sleep, which is great if you're building a battery

9
00:00:50,460 --> 00:00:53,430
powered gadget and things of that sort.

10
00:00:53,850 --> 00:00:59,640
In this first lecture of this section, as I mentioned already, I'm going to demonstrate how you can

11
00:00:59,640 --> 00:01:06,270
use the hardware timers that are integrated into your E.S.P to every scene.

12
00:01:06,270 --> 00:01:13,350
How to use at least one of those times in previous lectures has assured you, for example, how to control

13
00:01:13,350 --> 00:01:21,600
in ality using a timer instead of using an infinite loop or other types of loops just to begin with.

14
00:01:21,690 --> 00:01:27,510
You can have a look at the documentation right here in the macro Python website.

15
00:01:27,510 --> 00:01:30,540
And I'm looking at quick reference for the E.S.P 32.

16
00:01:30,540 --> 00:01:36,540
And the time is that's where you learn that the E.S.P 32 comes with four hardware.

17
00:01:36,540 --> 00:01:44,850
Time is integrated and the way to use them is to import the time a module from the machine module and

18
00:01:44,850 --> 00:01:46,830
then set them up like this.

19
00:01:47,090 --> 00:01:52,820
You indicate through the perimeter here of the time a module which time it is that you want to use in

20
00:01:52,830 --> 00:02:00,930
a to in a day from zero to three, and then you initialize the time you need to indicate the period

21
00:02:01,470 --> 00:02:06,150
and then the type of mode that you want to set the timer for.

22
00:02:06,160 --> 00:02:08,220
So either a one short time.

23
00:02:08,280 --> 00:02:11,780
So this is going to fire once or periodic in this case.

24
00:02:11,820 --> 00:02:15,690
This time it's going to fire every 2000 milliseconds, every two seconds.

25
00:02:16,110 --> 00:02:20,610
And then what is it that you want to do in particular?

26
00:02:20,610 --> 00:02:25,650
What kind of functions would you like it to call once the time expires?

27
00:02:26,010 --> 00:02:35,850
You can either use a lambda lambda is simply a tiny function that you can embed into the parameter itself,

28
00:02:36,180 --> 00:02:40,530
or alternatively, you want to go for something more traditional and classic.

29
00:02:40,530 --> 00:02:49,770
You can set a interrupt service routine like I've done here, which is just a regular function that

30
00:02:49,770 --> 00:02:52,480
is being called when the timer expires.

31
00:02:53,220 --> 00:02:57,820
So as I said, you can use up the full timers in my example.

32
00:02:57,840 --> 00:03:06,600
So what I do wish to use and IGB ality, which contains three component abilities in the same package,

33
00:03:06,600 --> 00:03:07,950
red, green and blue.

34
00:03:08,070 --> 00:03:11,250
And you see, I've set that up on my breadboard.

35
00:03:11,490 --> 00:03:21,750
I've got the red segment connected to Tapio 21, the blue segment connected to Jhpiego 22 and the green

36
00:03:22,140 --> 00:03:25,200
connected to your twenty one a23 sorry.

37
00:03:25,920 --> 00:03:35,820
And I have set up three hardware timers, each one set up to have a slightly different period.

38
00:03:36,120 --> 00:03:42,630
So you can see that the first one here I did zero time sensitive period of 250 milliseconds and when

39
00:03:42,630 --> 00:03:51,210
that expires it will call the red blink itself, which is this method right here or this function right

40
00:03:51,210 --> 00:03:51,510
here.

41
00:03:51,780 --> 00:03:58,380
Then time, although the a slightly different period, 350 milliseconds that's going to call the blue

42
00:03:58,380 --> 00:04:00,840
blink ISO, which is right here.

43
00:04:01,080 --> 00:04:04,770
And finally, the last one is timer with ID Editta.

44
00:04:05,100 --> 00:04:11,490
It's got a period of four hundred and fifty milliseconds and that's going to call the green blink guess

45
00:04:11,730 --> 00:04:12,750
which is right here.

46
00:04:12,760 --> 00:04:16,170
And those will just simply turn the lights on and off.

47
00:04:16,650 --> 00:04:21,960
And because the period is slightly off compared to each other, I'm getting some interesting effects

48
00:04:21,960 --> 00:04:25,440
that I think make the end result quite interesting.

49
00:04:25,990 --> 00:04:32,250
But the point here is that I've got three independent timers and each one, when it expires, it will

50
00:04:32,250 --> 00:04:40,650
call its own interrupt service routine and it will control your independently of all the others.

51
00:04:41,070 --> 00:04:42,720
You could add one more here.

52
00:04:42,730 --> 00:04:46,620
They could have a total of four hundred titles.
