 This right here is the TTP-229 capacitive touch matrix module, which is just a long way to say touch keyboard. Just like in the last video, it can sense the touch of a finger, but this time we have 16 of those capacitive touch sensors on this board. In the last video, we went over a single capacitive touch sensor and how it works, how to connect it with code, how to connect the wiring and how to make it work so you can integrate it into your own project. And in this video, we're going to be doing the same thing, but with a little twist. And now we have to do 16 of them. I also mentioned in the last video that these work like modern phones or modern screens that you would see on iPads, iPhones, smartwatches, TVs, car screens, and more. That's because capacitive touch screens or modules like this one are coated with a conductive material that can store an electrical charge. And when your finger comes in contact or even close to that device, it alters the screen's electrostatic field at that specific point. That's because the human body can conduct electricity and therefore it changes the capacitive, which is where the word capacitive sensor comes from. And that word just stands for the ability to store an electric charge. And the screen of a smart device kind of works like this, where you can imagine there's lines that separate everything. On a screen, you have thousands of them, maybe even hundreds of thousands, I'm not sure on the exact number. And depending on the size of the touch screen, but here you could see that we have 16. Now what happens is when the screen is divided into a grid of tiny invisible wires, each point on this grid has its own capacitance. Just like here, each button has its own sensor or its own capacitance. When you touch the screen, the device measures the change in capacitance at those specific points or even multiple points. And that precise measurement allows the device to pinpoint where the touch is and for it to be accurate. So when you touch on that button to buy something on a store on your phone, when you want to go back or you want to delete or you want to type on the keyboard, that's how it works. And modern capacitive screens, like the ones we've been seeing in the past couple of years can actually do multiple points at once. Like when you're on a map or you want to zoom into a picture, you kind of take your fingers and you open them up or you close them, you spin them. All these movements, it's multiple touch points at once. I think it's a dying trend, but actually with some phones you would get a stylus pen or with the iPad, you get the iPad pen, which allows you to be even more precise because if I take my big finger and I put it in the middle of these four buttons, I'm gonna click all of them at once. With a pen, you could be a little bit more accurate on what you're pointing and what you're pinpointing, which helps a lot with applications like drawing, designing or any type of thing where you really have to be specific with what you're doing. Those pens usually have a material on them that is conductive, like a conductive rubber or metal. And yeah, so it just helps with the finger being so fat that when you use a pen, you could be more specific. That's it. All right, well, let's do a little demo of this thing and I'm gonna show you how it works. It's a little bit hard to see, but I made a little modification here so that we can use the least amount of cables on this project. As you can see, when you go three to the right, I connect the top and the bottom together with this little jumper cable and it's not even soldered in, it's just a loose cable. I would recommend soldering it for this demo because eventually I want to reverse this. I'm not gonna solder it. We're gonna be using four pins for this project, the VCC, the ground SCL and the SDO. So get four cables, connect them up and let's get started with the demo. So we're just gonna plug in a power cable into VCC, ground, ground, one for SCL and one for SDO. VCC is gonna go into five volts on Arduino, ground is gonna go into ground. SCL is gonna plug into number 10. The picture I put on the screen, I think it's plugged into nine and eight, so just make sure you plug it into 10 and then the SDO is going to plug into 11. By doing this, we can use the electronics that are on the actual module so we can reduce the amount of cables because there is another way to do this where you kind of do all the work yourself like you would do with an LED matrix, which we've done before in a previous video. And as you can see, it's a lot of cables comparing to this setup. And in our case, it's gonna give us the same outcome, so we're gonna do it this way. So I'm just gonna connect the Arduino to the computer and we can get started with the code. Start off with an empty file and the first thing we're gonna do is add our variables. Since we're only using two wires for information, we're gonna be declaring our SCL, SDO, SCL to 10, SDO to 11. After that, we're gonna have to declare a little placeholder, which is just gonna be a byte called key. This is gonna store the information that's coming from the board. So whatever key we press, we're gonna store it in that key variable. To print something to the console, we have to do our serial.begin as always and we have to declare our pins, which SCL is going to be an output pin and SDO is going to be an input pin. Then we're gonna go to the loop and we're gonna do a couple of different things. First off, we're going to read our key and we're gonna be using read keypad, which is not an existing function. We're gonna have to make this ourselves later on in the code. So once we read our key, we're gonna have to do something with that information. This little if statement just ensures that if a key is pressed, we're going to be printing out its value. If not, we're just gonna be passing on and redoing the loop after a one millisecond delay. This if statement is just gonna ensure that if the key is being pressed, if it's equal to something, it's gonna be printed in the console and if it's not, we're just going to delay and redo the loop. So every 100 milliseconds, it's gonna check if the key has been pressed. So that's it for our setup and Luba, what we're gonna do now is make a function. The purpose of this function is just gonna be to read the keypad and give us a key that we can store. We don't have to put anything into the function because it's void and we're just gonna be declaring a byte because that's what we're gonna be getting back from the function, which is why we stored key as a byte up here just to match the type. First thing we're gonna start with is two variables, one count and one key state. These are gonna be holding information while we do a loop. Our loop is gonna scan each key on the keyboard and see if it's being pressed. So it's gonna go from one all the way to 16. Unfortunately with Arduino, it can only do one thing at a time. It's not multi-threaded. Unfortunately with Arduinos, they can't do everything at once. They have to do one step at a time and move on to another once it's been done with that. So in a loop, what we're gonna do is count from one to 16, which means we're gonna be going through every key and checking if it's being pressed. The process of checking if it's being pressed is pretty simple. We set SCL pin to low, then we check SDO pin if it's being pressed. If SDO pin is being pressed, then we know that whatever account is equal to because we're counting one through 16, whatever count we're on. So if we're on count number three and suddenly SDO pin says we're pressing something that we know then button three is being pressed. That's why we store the count over here and then here we could set it to our key state and then here we write SCL pin high when we're done with that key, we move on to the next. Once we find out what key is being pressed, if any is being pressed, we're just going to, let me add the comment there, we're just gonna be returning key state which is what we're setting over here, which is count and count is the counter in the loop. So after all that, we could kind of minimize it right here. We're going to just check what key is being pressed by checking all of them and then looping over and over and over. And then if we were to get anything out of our little function here and put it to key and it existed, we'd be printing it out to the console. So it's a bit of a mess, but you can kind of see how the steps go one by one. But still, I believe this is way better than doing it the way where you have all the rows and all the columns plugged in with cables because again, look at the picture, that's a lot of cables and it's not any less code. All right, so we could save that, we can plug in our board and we can upload it to the board to see what happens. Now I'm just going to go into tools and open up serial monitor. And then down here, we can clear the serial monitor. Now there should be nothing in the serial monitor until we click a button. So I'm just going to put my button on number seven. And as you can see, we're getting number seven. If I do one, two, three, four, five, six, seven, eight, nine, 10, 11, 12, 13, 14, 15, 16, they all work. It's a little bit hard to show, but there you go. And you can see sometimes if I don't give it good contact or I press between the two, it kind of jumps around. But that's kind of what the precision thing that I was talking about earlier with my finger being very fat for a sensitive sensor like that. But again, if I click on one, I click on six, I click on two, five, all those work really nice. And it's super quick. We're only putting a hundred millisecond delay. And I mean, if I hold the button, it's just going to print it out endlessly. So you can imagine that if this was your iPhone screen and you had, let's say the backspace button here, you had the enter button here, whatever, whatever, you would just click on that, you would click on that and it would be able to differentiate where your finger is on the board. Like if I was to suddenly put a screen over this, I can use these sensors to figure out where on the screen I'm pressing by moving my finger around. And as you can see, that reflects right away in the code. Moving around, I'm on seven, I'm on 14, 13, I'm on 15, I'm on 16. As long as I move my finger around, you could see where I'm at. So hopefully that gives you a cool idea of how modern technology evolves for something as simple as a single capacitive switch. It's pretty cool to see how most complicated technologies are just things that we use in our normal lives, but reduced to a tiny, tiny size so that we can have precision. Just how the basic screen that you might have on a toaster or microwave is kind of the same thing that you have on your iPhone, but way, way more zoomed out. And on the iPhone, it's way more compressed and small to make a high resolution. If you enjoyed this type of content and it helps you out in learning and figuring out how to do the code and wiring and all that, do me a favor and subscribe to the channel. For some reason, YouTube only notifies people that are subscribed to the channel. So if you want to see more of this kind of content, subscribing helps out a lot. If you have any questions or concerns about this project or something that I might have done wrong or missed, please let me know in the comments so I can fix it in the next video. And if you need any help with your project, join the Discord, there's a lot of people out there that can help you out with your problems. Not sure what we're doing in the next video, but I'll see you then.