All right.
Welcome back.
So let's continue the fact must compile and rebuild our program to see how it looks so far.
Click here to rebuild our margins.
And we've got zero errors two warnings.
So let's start by creating the prototype of our functions.
Just copying each function and put it up here and it's it's called on at the end.
Then copy this as well
plays this up here dance and call them then which add a function we have to put in it to function.
This place it up here in the corner.
Then the final function which is to measure distance.
Copy this and then put here as well to form function.
Let's just fix this over here.
OK.
Floyd says nice.
So let's test our code.
We stopped by calling the port in its function to initialize our GPL you pot.
And then we initialize time of zero from the time as you need to function like this.
Then we create a while 1 Loop infinite loop.
And what I'm going to do is just going to create a new local variable or I'll make it a global variable
to code the return.
But the use of the measure de function I'm going to call this new variable you 8 in 32 distance in centimeters
and we're going to start a return for you both with the measured dysfunction in this in this variable
like this.
So this variable would have the distance centimeters.
And once this is measured we can in fact use the M the decision or the funding here to perform other
functions.
Well I'm going to do it.
I'm going to see.
I'm going to check if the distance between the object and the orcas will make sense or is it less than
the 16 centimeters then 10 on the plurality.
That is why we initialize the entity just to create this so we can just see if mission D is less than
15 10 on the LCD.
I know I'm using Measure D here and it looks as if our distance in centimeters spread well it's useless.
I put this here because when we go to the debug view I want to up this variable to the watch window
and see as it finally changes when I move my hand up and down on top of the okra or in front of the
ultrasonic sense or so let's compile and see it all good and I'm going to download onto my board
still.
Good
so the next step is.
Hook up your ultrasonic sensor according to this schematic.
You can connect the FEC to the ultrasonic to another microcontroller that has a five root source or
in fact if you have a five volt battery five volt adapter or a five foot power supply you can connect
the PCC to the five or 10 in the ground to the ground of that particular five source.
This is because the TWC Launchpad provides just three point three vote and the ultrasonic sensor requires
five fold to operate.
I tested on the three point three Volt and it wasn't working well.
So to get its 5 volt and connect it to when that is done and it's connected and you've downloaded everything
you need to come to the debug view like this.
And what we need to do is add this variable here to the watch window right away.
Double click like this.
And then right click and select a distance and see what we know why we have it over here now.
It could click on right click and then on.
Check this to display the number in decimal mode so to run the code you simply press this and it could
just run it.
Karen Lee this the distance in centimeters cause the ultrasonic sensor is just pointing upwards.
So basically does the distance between the sensor or in my ceiling.
I'm sitting in a room not very high.
It's two point three meters the ceiling from the table.
So that's the voltage sometimes.
My hand is above it.
No I'm moving closer.
Way way.
And as you can see the blue lights on and it's staying on.
This is because we've just set it to stay on.
We've not added else condition saying if the distance is greater than or less than 15 go off this condition
just turns it on.
There's no other condition that tennis it off.
So we can just change that now and then make sure the light is fully turned on when the measured distance
is below 15 centimeters.
So I'm going to do that now and then run it again and we see
I'm going to say ls shortest way to solve this is to use on as an Ellis statement just see ls
just to say this sentiment in activities like this.
This the same much writing 0 0 0.
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
in just that pin of the blue LCD.
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
hand the goes on as well.
And this is it guys.
This is how you can use fuse timers to right other drivers.
So in the next and final section we're going to learn about timer interrupt going to learn about how
to use time is to invoke interrupt.
And with that we would complete the the cortex in time is cookbook.
We've covered all the major in fact everything you need to know about timers.
So I'll see you in the next lesson.