Now that we are done with the LED blinking example, let's move on to the touch sensor example.
This is a new cool feature that's available on the ESB 32 balls.
VSP 32 has internal alternate internal capacitive touch sensors.
We already explained or showed these pins.
We already showed.
We already explain this bends and the wiring layout of the speaker to listen.
But let's talk about them again.
Now these 10 antenna capacitive touch sensors can be used as buttons, and there are numbers from general
purpose input output number four zero two, 12, 13, 14, 15, 23 or 32, 33 and 27.
These are the pins.
I will show you the beans.
No number one minute.
Okay.
OK, this is it, and you can refer to the wiring layout or the pin diagram lesson where you can see
these pins.
These are thin internal capacitive touch sensors that you can easily use in order to read these pins.
What you need to do is use the function, touch read, and this function will take only one variable,
which is basically this is the function that usually takes one variable, which is the pin number,
the symbol, number four, number five, and so on.
So.
In order to use this function first, we need to assign a variable.
Now we can't right and value.
And I touch Reid
inside the twilight, and no, we can't use the all-purpose input-output for which basically the first
touch sensor t0.
And now let's create a code where we read the state of this touch sensor and submit on the serial monitor
to do this.
First, you need to.
Initialize the communication and the setup method, as you can see between these two curly parentheses.
So light serial dot begin
and use any Mod. We can use 150000 200s.
And let's add some delay to help it
stabilize.
One second now.
Let's try this nonsense.
Let's try cereal, dot, print.
Yes, beef as a tool.
Touch
this.
Now we have to set the pin moment for us output, we want to use the LEDs as an indicator for the touch
straight or touch sensor state.
So we have pin number two, which has the lid and we need it as output.
We also need to write a value and make sure that it equals zero.
We want to make sure that the lid is off.
To do so, we need to write that pin number and light law.
Using this line, we are making sure that when the yes people starts, it will make sure that that it
is off.
It will only turn on if there is touch all of the touch sensors on.
OK, now what we need to do next is read the value Dutch read using Dutch read and stored up inside
the value.
Now we want to ask our question if the Dutch value is above or below a certain value, we can turn on
or off than it.
But before we do that, we can't simply print the touch, read all the value that we get from touch
speed sensor, which is the capacitive touch sensor on the serial monitor.
So let's get let's do this serial dot print online and inside it.
We need to place the value.
After that, we can add a delay on second delay.
Now, let's try combining our code.
Let's store it inside.
Our coding folder.
It's called a touch
screen, for example.
OK, let's remove these.
Now, let's combine a game.
OK.
Duncan compiling.
Now let's upload the code to our ISP board.
By the way, you can use number four, which is the pin number, or you can use t0 do you 182 up to
210 because we already mentioned that we have, uh, 10 touch sensors.
Now let's open up the serial monitor.
OK.
As you can see, that much value here is hundreds.
And seven, and if we did touch it, it will change.
Let me do that.
OK, now, as you can see, we have seventy four, thirty seven, 71, 70.
Now let me touch the pin.
As you can see, once I touched upon the values of goal below, then.
And when I leave it.
Goes again up to seventy seven to two.
So I think that we have a consistent value here.
If the value is below 50 means that I'm touching the pin.
If it is above 50 means that I'm not touching the pin.
We can adjust our code accordingly.
Now let's do that.
Now let's go here.
And if statement now in that statement, we are going to ask a question, the value is above all equal
50.
And it's more of this side of this.
So super he is now in that case, we need to turn on the red.
And add a delay.
Ms.
If the value is.
Below 50,
we need to turn the lid off.
OK, now let's verify our code.
Oh, and let's print a sentence and say these two statements using the serial plant.
So he is going to plant lid on.
And here we going to try led off.
Let's verify the call again.
OK, now let's applaud, according to the SB 32 board again.
The process takes some time.
Now it's connecting to the board.
Now it's writing the code.
OK, done uploading.
Now, if we open up the serial monitor, as you can see, the light is on.
And if you take a look to your board, you can see that the lid is on.
Now, let me touch the Touch Pen, as you can see, the value goes below 50 and the lid is off.
That's it.
This is how easily you can use and adjust the touch sensor inside the SB 32 board.
It's built in so you don't have to connect any extra components.
This is how amazing it is and how easy it is to deal with this ball.
If you have any questions regarding this pen, I'm here to help you.
Thanks for watching this lesson.
This is us from educational engineering team.