I have a working code with 4*4 matrix keyboard, it's tested and working. I've just got a keyboard like this one
And I'm trying to make it work with the same code, I'm able to print the inputs but cannot store and compare them.I guess the problem is here uint16_t customKey = ttp229.ReadKeys16(); if I remove uint16_t , then I cannot read keys anymore
#include <TTP229.h>
#define Password_Lenght 4
char Data[Password_Lenght];
char Master[Password_Lenght] = "111";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
const int SCL_PIN = 2; // The pin number of the clock pin.
const int SDO_PIN = 3; // The pin number of the data pin.
TTP229 ttp229(SCL_PIN, SDO_PIN); // TTP229(sclPin, sdoPin)
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("Hello");
}
void loop()
{
uint16_t customKey = ttp229.ReadKeys16(); // I think the issue is here uint16_t
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Serial.println(customKey);
beep (50);
Data[data_count] = customKey; // store char into data array, after this data looks empty!
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master
{
if(!strcmp(Data, Master)){ // equal to (strcmp(Data, Master) == 0)
Serial.println("Good");
beep (500);
beep (500);
}
else {
Serial.println("Bad");
beep (50);
beep (50);
}
clearData();
}
}
void clearData()
{
while(data_count !=0)
{ // This can be used for any array size,
Data[data_count--] = 0; //clear array for new data
}
return;
}
void beep(unsigned char delayms){
analogWrite(13, 200); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
analogWrite(13, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms
}