1
00:00:00,690 --> 00:00:03,090
Hi and welcome to a new look changes section.

2
00:00:03,540 --> 00:00:12,180
In the previous lecture, you learned how to make this link so disconnected to your 21 and you make

3
00:00:12,180 --> 00:00:15,230
that work by using the while loop.

4
00:00:15,260 --> 00:00:23,670
You've got a while true loop here that never ends and it will just turn on the on and off and each time

5
00:00:23,670 --> 00:00:27,060
it'll keep its state for half a second.

6
00:00:27,540 --> 00:00:33,840
In this lecture, I want to show you an alternative way of making this ability to blink, and that is

7
00:00:33,840 --> 00:00:37,910
by using a hardware timer instead of a loop.

8
00:00:38,370 --> 00:00:41,460
So I've got this script right here.

9
00:00:41,520 --> 00:00:49,710
It's five twenty and you can see it's about the same size as the blink with the wild true loop.

10
00:00:50,010 --> 00:00:52,140
But now we are using a timer.

11
00:00:52,150 --> 00:00:54,590
You can see that I'm setting the timer down here.

12
00:00:55,260 --> 00:00:59,880
This timer has an I as are assigned.

13
00:00:59,880 --> 00:01:10,140
This is an interrupt service routine assigned, which is a simple function that inside that function,

14
00:01:10,140 --> 00:01:16,110
all it does is that they will check the current value of the ability by using the value function.

15
00:01:16,380 --> 00:01:23,190
And if it is false, therefore the elite is turned off and it will turn the lights on and if it's not,

16
00:01:23,580 --> 00:01:24,620
it will turn it off.

17
00:01:25,260 --> 00:01:28,920
So the logic here is that we don't have an infinite loop.

18
00:01:28,920 --> 00:01:35,880
We just have a hardware timer which is connected to a routine that contains the functionality that we

19
00:01:35,880 --> 00:01:41,630
want, whether in this case it is to blink an on and off or to do something else periodically.

20
00:01:42,270 --> 00:01:48,770
The new thing to learn here is the use and the configuration of the hardware timer.

21
00:01:48,790 --> 00:01:57,090
And you can see that here I've got a Eurail, a link to the documentation where you can look it up and

22
00:01:57,300 --> 00:01:58,380
learn more about it.

23
00:01:58,620 --> 00:02:00,690
But as you can see, it's quite simple.

24
00:02:00,900 --> 00:02:07,980
I'm looking inside the quick reference for E.S.P 32 times instead of this paragraph here, which contains

25
00:02:07,980 --> 00:02:10,840
the way to use a hardware timer.

26
00:02:11,310 --> 00:02:18,370
So first, we need to start by importing the time a module from the machine module here, we create

27
00:02:18,370 --> 00:02:20,310
the timer object to give it a day.

28
00:02:20,310 --> 00:02:21,660
It doesn't need to be a negative number.

29
00:02:21,660 --> 00:02:31,860
You can see here that I just said timer parentheses one for the ID and then you can set that time up

30
00:02:31,890 --> 00:02:34,440
to whichever interval you want.

31
00:02:35,430 --> 00:02:39,420
There's the init or initialization function and it takes these parameters.

32
00:02:39,420 --> 00:02:40,710
First you've got the period.

33
00:02:41,160 --> 00:02:49,920
So how often which it like this time to call your function then the mode it's going to be a one shot,

34
00:02:49,950 --> 00:02:55,920
which means the time it's going to trigger once and then it will stop or periodic, which is what we

35
00:02:55,920 --> 00:03:02,040
are doing in this example, which means that the time I was going to call your you will retain your

36
00:03:02,040 --> 00:03:05,010
function every time that the period elapses.

37
00:03:05,580 --> 00:03:07,440
And then we've got a call back here.

38
00:03:07,440 --> 00:03:15,300
The callback is a Lambda Lambda is a python feature that allows you to define a very small function

39
00:03:15,300 --> 00:03:15,960
in line.

40
00:03:15,960 --> 00:03:23,910
So instead of defining the function as we are doing here, right here, somewhere else in your program

41
00:03:24,420 --> 00:03:30,300
with the lambda, you define your function in line with the callback declaration.

42
00:03:30,810 --> 00:03:37,170
And this case is just going to print out one which in this case, the lung function printshop out to

43
00:03:38,650 --> 00:03:46,260
also want to show you the full class time on module that comes with the macro python firmware.

44
00:03:46,560 --> 00:03:48,990
And you can see how it works here.

45
00:03:49,440 --> 00:03:51,150
A little bit more information about it.

46
00:03:51,420 --> 00:03:59,220
You can see that the mode can be that this one short or periodic, and you can also use the Internet

47
00:03:59,220 --> 00:04:01,740
to initialize it time and basically stop it.

48
00:04:01,860 --> 00:04:08,970
Disable it if needed properly, can enable it by using in it and then you can disable it by using the

49
00:04:08,990 --> 00:04:09,450
Internet.

50
00:04:09,720 --> 00:04:12,470
We are just enabling it by using init in this example.

51
00:04:12,540 --> 00:04:14,430
There's no reason to initialize it.

52
00:04:15,090 --> 00:04:16,710
And there's the constants.

53
00:04:16,950 --> 00:04:23,610
And it's a very simple way to take advantage of the hardware time in the E.S.P three to.

54
00:04:25,100 --> 00:04:32,450
So the next thing to do here is to upload this script to the ISP 3-2, so I'm going to use the save

55
00:04:32,450 --> 00:04:35,970
a copy method so they will go to the market python device.

56
00:04:36,000 --> 00:04:38,400
OK, so I'll do this again to see what happens.

57
00:04:38,420 --> 00:04:45,500
So I tried to make a copy to make a Python device, but as you can see, the device is busy right now

58
00:04:45,860 --> 00:04:50,980
because it still running the sketch from the previous lecture.

59
00:04:51,380 --> 00:05:00,280
So I first have to stop the execution of the script to interrupt it and then copy the new script along.

60
00:05:00,620 --> 00:05:01,850
You can do that a couple of ways.

61
00:05:02,180 --> 00:05:08,630
The first one is to hit control, see, and that will stop the execution of the script.

62
00:05:09,080 --> 00:05:16,190
Or you can go to run and choose to interrupt execution option, which is, as you can see, control

63
00:05:16,190 --> 00:05:17,770
see from the menu.

64
00:05:18,110 --> 00:05:24,410
So I'll do that via the menu this time and from now on, which I'll be using my keyboard to do a control

65
00:05:24,410 --> 00:05:26,810
see and interrupt execution.

66
00:05:27,890 --> 00:05:28,280
All right.

67
00:05:28,290 --> 00:05:37,350
So let's try again our fail safe copy Micro Python, and I'm going to give you the same name ality link

68
00:05:37,910 --> 00:05:39,150
timer here.

69
00:05:39,260 --> 00:05:44,360
Why I got the twenty one for the GPO.

70
00:05:45,440 --> 00:05:48,620
Right, so here it is.

71
00:05:48,620 --> 00:05:49,820
Double click to bring it up.

72
00:05:50,900 --> 00:05:56,870
All right, so now I'm going to make sure that I've selected the blink time.

73
00:05:56,910 --> 00:06:05,300
I've got to wonder why a script with the square brackets that is the one that is stored on the 32 and

74
00:06:05,300 --> 00:06:12,500
with that selected or pressed the play button, the green play button, or go to run and click on run

75
00:06:12,500 --> 00:06:13,400
current script.

76
00:06:13,730 --> 00:06:15,220
And that will have the same effect.

77
00:06:15,230 --> 00:06:18,110
So click on that and.

78
00:06:19,780 --> 00:06:23,020
You can see that the effect is exactly the same as before.

79
00:06:23,380 --> 00:06:30,830
So we've got the deep thinking I can change the hardware time to make it blink a little faster.

80
00:06:30,850 --> 00:06:36,470
So let's make this two hundred and fifty milliseconds just to see the difference between description

81
00:06:36,470 --> 00:06:40,180
and ensure that this is the one that is really being executed.

82
00:06:40,660 --> 00:06:49,780
So I made a small change here to the period and then click on Save to save it to the device and then

83
00:06:49,780 --> 00:06:53,140
click a. on the green play button.

84
00:06:53,800 --> 00:06:57,400
And you can see that the elite is now blinking faster.

85
00:06:58,100 --> 00:07:04,120
The other thing that is interesting is that I can make changes and save them or make them say two hundred

86
00:07:04,480 --> 00:07:06,790
milliseconds and I'm going to save it.

87
00:07:07,990 --> 00:07:15,910
And you can see that there was no complaint from Sony to complain that the device is busy, like there

88
00:07:15,910 --> 00:07:21,790
was a complaint earlier when we were running the ality blink with the while loop here.

89
00:07:22,240 --> 00:07:29,050
And that is because when we were using the wire loop, the device was really engaged, either making

90
00:07:29,050 --> 00:07:30,720
the little blink or sleeping.

91
00:07:31,300 --> 00:07:33,290
So the device was engaged.

92
00:07:33,310 --> 00:07:34,780
We couldn't save on.

93
00:07:34,780 --> 00:07:41,050
I can make any changes, but when we are running the script with the interrupt, the device is only

94
00:07:41,050 --> 00:07:50,980
busy when the timer is actually calling the isobutane and only when the security is executing these

95
00:07:50,980 --> 00:07:53,910
highlighted lines and all other times it's not busy.

96
00:07:54,310 --> 00:08:02,950
So it can be ready to receive, for example, a new file update from Sony without complaining about

97
00:08:02,950 --> 00:08:03,980
it being busy.

98
00:08:04,630 --> 00:08:06,490
So that's another positive effect from this.

99
00:08:06,490 --> 00:08:14,410
You can see that the use of the U.S. military to hardware is more efficient when we use the hardware

100
00:08:14,410 --> 00:08:17,660
time versus the while troop.

101
00:08:19,090 --> 00:08:26,830
All right, so let's move on and do one more experiment that involves the energy on Tiberio 21, which

102
00:08:26,830 --> 00:08:33,130
is learning how to make it fate using copes with modulation.
