1
00:00:03,680 --> 00:00:04,310
All right.

2
00:00:04,310 --> 00:00:05,660
Welcome back.

3
00:00:05,720 --> 00:00:14,040
So let's continue the fact must compile and rebuild our program to see how it looks so far.

4
00:00:14,300 --> 00:00:17,290
Click here to rebuild our margins.

5
00:00:17,390 --> 00:00:21,220
And we've got zero errors two warnings.

6
00:00:21,320 --> 00:00:25,050
So let's start by creating the prototype of our functions.

7
00:00:25,100 --> 00:00:30,940
Just copying each function and put it up here and it's it's called on at the end.

8
00:00:31,560 --> 00:00:33,230
Then copy this as well

9
00:00:38,910 --> 00:00:48,700
plays this up here dance and call them then which add a function we have to put in it to function.

10
00:00:48,880 --> 00:00:52,940
This place it up here in the corner.

11
00:00:54,040 --> 00:01:00,490
Then the final function which is to measure distance.

12
00:01:00,840 --> 00:01:13,540
Copy this and then put here as well to form function.

13
00:01:13,920 --> 00:01:16,070
Let's just fix this over here.

14
00:01:16,890 --> 00:01:17,440
OK.

15
00:01:17,550 --> 00:01:19,720
Floyd says nice.

16
00:01:19,980 --> 00:01:22,200
So let's test our code.

17
00:01:22,200 --> 00:01:29,010
We stopped by calling the port in its function to initialize our GPL you pot.

18
00:01:29,280 --> 00:01:36,630
And then we initialize time of zero from the time as you need to function like this.

19
00:01:38,130 --> 00:01:42,190
Then we create a while 1 Loop infinite loop.

20
00:01:42,540 --> 00:01:49,710
And what I'm going to do is just going to create a new local variable or I'll make it a global variable

21
00:01:49,740 --> 00:01:51,090
to code the return.

22
00:01:51,110 --> 00:02:02,550
But the use of the measure de function I'm going to call this new variable you 8 in 32 distance in centimeters

23
00:02:03,360 --> 00:02:13,590
and we're going to start a return for you both with the measured dysfunction in this in this variable

24
00:02:13,590 --> 00:02:14,170
like this.

25
00:02:14,220 --> 00:02:17,690
So this variable would have the distance centimeters.

26
00:02:17,940 --> 00:02:27,810
And once this is measured we can in fact use the M the decision or the funding here to perform other

27
00:02:27,810 --> 00:02:28,450
functions.

28
00:02:28,450 --> 00:02:29,630
Well I'm going to do it.

29
00:02:29,640 --> 00:02:31,920
I'm going to see.

30
00:02:32,070 --> 00:02:38,640
I'm going to check if the distance between the object and the orcas will make sense or is it less than

31
00:02:38,640 --> 00:02:43,180
the 16 centimeters then 10 on the plurality.

32
00:02:43,200 --> 00:02:51,450
That is why we initialize the entity just to create this so we can just see if mission D is less than

33
00:02:52,920 --> 00:02:54,850
15 10 on the LCD.

34
00:02:54,990 --> 00:03:01,530
I know I'm using Measure D here and it looks as if our distance in centimeters spread well it's useless.

35
00:03:01,530 --> 00:03:07,230
I put this here because when we go to the debug view I want to up this variable to the watch window

36
00:03:07,320 --> 00:03:14,880
and see as it finally changes when I move my hand up and down on top of the okra or in front of the

37
00:03:14,940 --> 00:03:25,530
ultrasonic sense or so let's compile and see it all good and I'm going to download onto my board

38
00:03:28,740 --> 00:03:29,070
still.

39
00:03:29,080 --> 00:03:29,570
Good

40
00:03:32,920 --> 00:03:34,900
so the next step is.

41
00:03:34,960 --> 00:03:38,650
Hook up your ultrasonic sensor according to this schematic.

42
00:03:38,650 --> 00:03:45,490
You can connect the FEC to the ultrasonic to another microcontroller that has a five root source or

43
00:03:45,490 --> 00:03:53,530
in fact if you have a five volt battery five volt adapter or a five foot power supply you can connect

44
00:03:53,980 --> 00:03:59,550
the PCC to the five or 10 in the ground to the ground of that particular five source.

45
00:03:59,560 --> 00:04:06,650
This is because the TWC Launchpad provides just three point three vote and the ultrasonic sensor requires

46
00:04:06,910 --> 00:04:08,770
five fold to operate.

47
00:04:09,090 --> 00:04:13,350
I tested on the three point three Volt and it wasn't working well.

48
00:04:13,360 --> 00:04:19,870
So to get its 5 volt and connect it to when that is done and it's connected and you've downloaded everything

49
00:04:19,930 --> 00:04:22,200
you need to come to the debug view like this.

50
00:04:22,200 --> 00:04:28,430
And what we need to do is add this variable here to the watch window right away.

51
00:04:28,540 --> 00:04:29,860
Double click like this.

52
00:04:29,890 --> 00:04:36,520
And then right click and select a distance and see what we know why we have it over here now.

53
00:04:36,710 --> 00:04:40,880
It could click on right click and then on.

54
00:04:40,890 --> 00:04:47,630
Check this to display the number in decimal mode so to run the code you simply press this and it could

55
00:04:47,630 --> 00:04:48,430
just run it.

56
00:04:48,520 --> 00:04:55,060
Karen Lee this the distance in centimeters cause the ultrasonic sensor is just pointing upwards.

57
00:04:55,150 --> 00:04:59,200
So basically does the distance between the sensor or in my ceiling.

58
00:04:59,200 --> 00:05:01,630
I'm sitting in a room not very high.

59
00:05:01,630 --> 00:05:06,260
It's two point three meters the ceiling from the table.

60
00:05:06,260 --> 00:05:07,900
So that's the voltage sometimes.

61
00:05:08,260 --> 00:05:09,250
My hand is above it.

62
00:05:09,250 --> 00:05:12,440
No I'm moving closer.

63
00:05:12,850 --> 00:05:16,050
Way way.

64
00:05:16,530 --> 00:05:20,060
And as you can see the blue lights on and it's staying on.

65
00:05:20,290 --> 00:05:22,850
This is because we've just set it to stay on.

66
00:05:22,850 --> 00:05:31,450
We've not added else condition saying if the distance is greater than or less than 15 go off this condition

67
00:05:31,450 --> 00:05:32,940
just turns it on.

68
00:05:32,940 --> 00:05:35,860
There's no other condition that tennis it off.

69
00:05:35,860 --> 00:05:43,030
So we can just change that now and then make sure the light is fully turned on when the measured distance

70
00:05:43,150 --> 00:05:45,970
is below 15 centimeters.

71
00:05:46,030 --> 00:05:49,660
So I'm going to do that now and then run it again and we see

72
00:05:52,840 --> 00:06:01,270
I'm going to say ls shortest way to solve this is to use on as an Ellis statement just see ls

73
00:06:04,630 --> 00:06:09,390
just to say this sentiment in activities like this.

74
00:06:09,460 --> 00:06:11,790
This the same much writing 0 0 0.

75
00:06:11,980 --> 00:06:19,990
But if I race here x years you're going to disable audit pins in GPI f whereas if I do this I'm disabled

76
00:06:19,990 --> 00:06:23,270
in just that pin of the blue LCD.

77
00:06:23,620 --> 00:06:32,850
So I'm going to rebuild and I'm going to download onto my board and as you can see when I take off my

78
00:06:32,850 --> 00:06:35,610
hand the goes on as well.

79
00:06:35,610 --> 00:06:36,900
And this is it guys.

80
00:06:36,900 --> 00:06:41,490
This is how you can use fuse timers to right other drivers.

81
00:06:42,000 --> 00:06:48,840
So in the next and final section we're going to learn about timer interrupt going to learn about how

82
00:06:48,840 --> 00:06:51,600
to use time is to invoke interrupt.

83
00:06:52,140 --> 00:06:58,650
And with that we would complete the the cortex in time is cookbook.

84
00:06:58,650 --> 00:07:03,470
We've covered all the major in fact everything you need to know about timers.

85
00:07:03,540 --> 00:07:05,600
So I'll see you in the next lesson.
