Hello.
Welcome back.
So in this lesson we agreed to write the function to initialize the touch sensor and then we're gonna
test it out.
So come over here to write a new function.
There's going to be a void.
I call this touch sensor or in it.
And this is simply going to call the on the touch sense or in its function in a while.
Both support package.
So simply say if I access the function in our PSP I'll see if PSP PSP.
Yeah.
On the score T S for such say so or touch screen
and then I'm going to initialize to 40 by 320 which is the size of the LCD screen of course.
Yes.
Area.
I'm gonna see if we are able to initialize it.
So by executing this line we initialize as well as check for error.
Right.
If that's the case we're simply going to print an error message see over here print f
touch sense of failure.
I'll go there.
Like this and we can delay for a bit how delay put 50 over here and I'm going to take this function
prototype to the top.
Copy and paste over here put a semicolon here.
So now we can call this in our main function or come to a main right off to initialize in our control
panel.
I'm going to initialize these types say so over here.
Write Okay so one thing with regards to this.
This function over here our control panel.
I changed a color from dark yellow to black.
This OCD color over here it sets text color used to be dark yellow and when I was taking the video and
a photo of my microcontroller board that color wasn't clear enough for the camera so I changed it to
black.
So in the previous lesson if you saw a dark yellow here and it's black now.
Yeah that's why it is black.
Course I changed it.
Okay so with initialized our touch saying yes or no let's call it you know what.
Infinite Loop we can call it.
I'll come over here.
We have a white infinite loop here I'm going to clean our global variable that we used earlier.
We use this for testing purposes.
I'll come over here and then I'm gonna make use of the function in our board support package.
I'll see BSP touch screen or touch since I'll get state
and I'm going to I'm going to create I'm going to create an instance of the t s state typedef and pass
it over here.
So I'll come over here and say t s on this call state typedef you know simply call this you a state
I'm gonna pass the address of this to our call down here put an ambush on here to grab the address put
a semicolon here right.
So we going to get state and then we can simply grow a circle or we can simply draw us we detect.
So what I'm going to do is I'm going to still come in here or should I write a new function for this.
Okay.
We can keep it here.
I'm gonna say if you I state you I state got touched detected.
If touch is detected.
I'm simply going to draw a circle or border.
I'll say BSP PSP underscore LCD underscore
full circle.
And then I'm going to draw the circle at the position so I'll see you I states dot X and then you isolate
the Y and then I'm gonna pass size 5 over here like this.
Okay let's build and see what we have.
Click over here to build
it's built successfully or connect my port and download a quick run and then debug over here.
Okay.
It's setting up
okay download complete.
I'm simply going to turn it off.
I'll terminate and then press reset on my microcontroller board the block button
and then I'm gonna test the touchscreen
I'm simply going to attempt to write something here.
Um yeah.
It's work in but it s a bit like in it s not flowing smoothly so we may have to debug somethin.
You see I'm trying to write to 6 but it s not perfect.
So the c word the error lies.
Okay um I suspect the cause of the sluggishness is from this function over here.
We can comment this out for now we're going to deal with it later and I'm going to add a bit of delay
down here.
Once we you know grow the um the picture.
Where you going to just delete
delay 1 over here okay.
No no C from the top or we have to have this the addresses of the LCD.
Oh this one here is missing a zero as well.
Okay let's build it see what we have now.
Click over here to build
and then click here debug to download onto the port
it's downloaded
it's still downloading
the download should be complete.
No.
Okay I'm gonna click here to run
she can see the LCD screen.
This is it.
I'm gonna attempt to draw something.
No it's smooth.
I just drew a 6 when I reset to my port right.
1 reset to my board and then 2.
In fact I'm gonna use a pointer to do this 6 3
2 Okay.
So now it s smooth and working perfectly.
Um yeah.
So the button doesn't work.
Now.
That's what we're going to do next.
We're going to isolate the bottom half of the screen from the top where we write so that we can we can
sort of press the reset button and have the screen you know erased.
So that's what we'll do next.
I'm going to exit that burger from over here
right.
So like I said we are going to separate the Boston area of the of this crane from the part where we
draw.
I'm gonna use a simple if statement over here I'm going to see if and I'll see you.
I do it okay.
It's called.
You state you I state that if you I state DOT x is greater than
the draw.
I m g we have we have a symbolic name that we call draw.
I m g X1 to draw.
I m g X1 if it s greater than this.
And you I state that X is less than X to just complete this
if it is less than x 2.
And we've got a check for y as well.
And
and I'll simply say you I Stage 1 Stage Two y
s greater than y one
and less than y.
Why you like this.
Why not put brackets here.
Yes you are.
We have you I state X if you have state X is greater than X one and less than X 2 and it's greater than
any other state.
Y is in the way I see it.
Why is greater than why one does sprockets should come up here
and your state.
Why is greater than why one and I state why is less than Why two.
If that's the case then we uh.
In the um we're in the growing area.
So in the groin area we simply perform our groin which we have over here feel.
Circle
ls we've got up put on else for the Portland area so I'll come over here and see who else
if you I state got x
is greater than you raise button cos we have a symbolic name known as erase button X as well say erase
button on the score x 1
and you y.
State X
is less than a race button x 2
Just fudge this
and then we do the same for y and you y state Y
is created than erase button y 1
and you I state that y s s done erase button y 2
if that's the case then we kinda erase zone see why do we have
a problem.
I'm simply going to open and close over here so let's check it you I state X is created on x 1 and US
states X is less than X 2 Over here it should be.
And then you y states Y is created and Y 1 and you y states Y is less than y 2.
If this is the case we are going to reset the game or cloud a UI and now we cleared a UI by taking it
to its default state which is control panel set over here.
Already have this we've created this function already
so I'll just paste this over here.
Now let's build and see what we have.
Click over here to build
okay and then I'm going to click over here to run by clicking on debug it s finished the book and I'm
going to click here to run and um.
Let's see.
Ron my board is frozen.
So I've got a text my board and put it back into the computer.
Sometimes I get this for the touch screen.
So here we go.
I've reset my port as you can see it looks the same.
Now I'm gonna write six and then I'm gonna press erase it s clean.
I'm gonna use a pointer to write a right to then I'll click you one raise three.
You rage just like that.
So the race button works.
Okay then right.
So in the next lesson what are we going to do is we going to take whatever we write over here in a large
area and shrink it to a twenty eight by twenty eight size.