1
00:00:01,110 --> 00:00:05,430
In this lecture, you have to read the state of the commentary button.

2
00:00:05,940 --> 00:00:11,970
I'm going to show you how to do that, using three different examples each time to bring a different

3
00:00:11,970 --> 00:00:16,340
capability of the ECB through in macro python to achieve the same thing.

4
00:00:16,350 --> 00:00:21,710
But each time with a bit more efficiency across the three examples, the hardware is not going to change

5
00:00:21,870 --> 00:00:22,680
in all cases.

6
00:00:23,190 --> 00:00:26,560
Have the ECB three to have a momentary pattern.

7
00:00:26,590 --> 00:00:32,760
She can see that is connected to Jebril for this pin right here.

8
00:00:33,180 --> 00:00:42,480
And I am using the ECB 32 internal pull up so that I don't need to use an additional wire to bring up

9
00:00:42,480 --> 00:00:47,970
the unpressed state of the button to high would use the internal pull up register for that.

10
00:00:48,330 --> 00:00:56,370
And I also have a wire here that will bring the state of the button to know when it's pressed.

11
00:00:56,610 --> 00:01:03,750
So that's what will be detecting to show, in effect of the button press I've got in here, just like

12
00:01:03,750 --> 00:01:11,040
in the previous lectures that is connected to Tapio 21 and that's about it with a hardware.

13
00:01:11,700 --> 00:01:17,610
In the first example that I'll show you in this lecture, I am reading the state of the button in the

14
00:01:17,610 --> 00:01:20,840
simplest possible way by using an infinite loop here.

15
00:01:21,240 --> 00:01:29,220
So I'm using the while loop than a passing true as its permanent state so that the program is going

16
00:01:29,220 --> 00:01:31,410
to be locked inside this block.

17
00:01:31,830 --> 00:01:40,260
So constantly it will be using this instruction to read the value of the button and if it is low represented

18
00:01:40,260 --> 00:01:41,060
by zero here.

19
00:01:41,070 --> 00:01:49,080
So logical state is low because you can see that the pressed state of the button is pushed down to zero

20
00:01:49,080 --> 00:01:55,410
volts, then will turn the old on and will stay there for ten milliseconds.

21
00:01:55,440 --> 00:02:03,090
And if the state of the button is not zero, it's one because of the internal pull up then will turn

22
00:02:03,090 --> 00:02:12,750
the ability of a couple of other things in this sketch worth talking about, I have used this expression

23
00:02:12,750 --> 00:02:21,480
here to declare the object of the button and you can see that I'm using the PIN constructor, just like

24
00:02:21,480 --> 00:02:24,180
I did with a PIN constructor for the ality here.

25
00:02:24,180 --> 00:02:27,200
But in this case, I've got three arguments.

26
00:02:27,210 --> 00:02:28,910
The first one is the GPO.

27
00:02:29,310 --> 00:02:35,820
The second one indicates that this is going to be an input and then the third one activates the internal

28
00:02:35,820 --> 00:02:37,040
pull up front.

29
00:02:37,170 --> 00:02:46,470
To learn more about the PIN constructor, have a look at this link here, which will take you to this

30
00:02:46,710 --> 00:02:51,120
page in the quick reference for the HB three two or the Micro Python website.

31
00:02:51,630 --> 00:02:54,960
And it shows you an example of how to use these functions.

32
00:02:55,230 --> 00:03:01,110
And again, if you want even more information than good to have a look at the machine Dot Pincott,

33
00:03:01,530 --> 00:03:03,660
which is this page right here.

34
00:03:04,530 --> 00:03:05,130
This is it.

35
00:03:05,460 --> 00:03:08,130
And you can see the constructors in my example.

36
00:03:08,130 --> 00:03:15,660
I'm using this constructor here to create an object for idea of the Tapio number for in our case then

37
00:03:15,660 --> 00:03:20,280
for mode, I'm using Penkin as opposed to pin down for the elite.

38
00:03:20,310 --> 00:03:22,140
This opinion is for the button.

39
00:03:22,500 --> 00:03:28,230
And then we also have the polyposis, stuff like that.

40
00:03:28,230 --> 00:03:32,580
So Pincott pull up is a way to turn on the pull up resistor you can see.

41
00:03:32,580 --> 00:03:37,590
And like the other, you know, you can also have the pull down resistor if you use Pendo, pull down

42
00:03:38,520 --> 00:03:39,810
and that's about it.

43
00:03:39,810 --> 00:03:43,190
The rest can be immediate and they will just take the default values.

44
00:03:43,920 --> 00:03:49,500
Another new thing that I'm using here is the tick and the call and this function.

45
00:03:49,500 --> 00:03:51,690
You can see that I'm using that down here.

46
00:03:51,870 --> 00:03:54,420
I'm importing it from you time.

47
00:03:54,840 --> 00:04:00,410
So from Micro Python version of the time, I see Python module.

48
00:04:00,780 --> 00:04:04,680
So this function here, you can get more information about it right there.

49
00:04:04,950 --> 00:04:09,590
It gives us the number of milliseconds since we have power to up the speed.

50
00:04:09,600 --> 00:04:10,140
Three, two.

51
00:04:10,350 --> 00:04:16,160
And that's because we want to see information about the moment that I pressed on the button and I'm

52
00:04:16,170 --> 00:04:21,840
bringing out the number of milliseconds since the activity was powered up when I pressed the button

53
00:04:21,840 --> 00:04:22,430
right here.

54
00:04:23,700 --> 00:04:24,990
OK, let's try this out.

55
00:04:25,170 --> 00:04:31,820
So at the moment, I've noted the script from my computer disk and my computer file system.

56
00:04:31,830 --> 00:04:41,340
So what I do is to save a copy with the macro python device in the name will be Button and it's call

57
00:04:41,340 --> 00:04:43,710
for the API.

58
00:04:46,110 --> 00:04:53,520
All right, here it is and double click on it to bring it up, you know, close the window that contains

59
00:04:53,520 --> 00:04:56,970
the version of the script on the computer file system.

60
00:04:57,580 --> 00:05:01,320
You know that I've got the script selected on the E.S.P 32.

61
00:05:01,320 --> 00:05:03,060
I will play it.

62
00:05:05,400 --> 00:05:17,530
All right, to press the button, you it is one text comes through to the show of my Thony Editor Button

63
00:05:17,530 --> 00:05:22,720
pressed, and then the number of seconds when the button pressed, it's been detected.

64
00:05:25,080 --> 00:05:25,500
All right.

65
00:05:25,950 --> 00:05:30,220
Obviously, this is not a very efficient way, again, to use the hardware.

66
00:05:30,240 --> 00:05:38,820
So I want to show you two additional methods of the set of a button that do not involve using a wire,

67
00:05:39,090 --> 00:05:40,950
at least not to do the reading.

68
00:05:41,370 --> 00:05:46,050
So let's have a look at the next lecture where I'll show you how to do the exact same thing more efficiently

69
00:05:46,050 --> 00:05:48,200
using a hardware interactive.
