I am trying to make a touch sensitive keypad with a password. When the correct combination in correct order is given, the lock will get unlocked. I use 2 x TTP223 capacitive touch sensor for test purposes, But I plan to use 14 of them. I use arduino nano for test purposes but will move on to arduino pro mini 5v.
I check for every "1" state input pin, then store them all in an array. Later on I check if the given input is already in the entry array. If it is, I skip. If it isnt, I add it. After that I check whether the given combination is true or not.
I use touch sensors in touch to lock mode, it means that the sensor is latched. When I trigger it, it stays on. When I press again, it turns off. This is why I check whether the input is already in the entry array or not. Unfortunately I dont have a schematic because I couldnt find a good schematic platform. Below is the code and my result in serial port.
code:
void checkRunes();
void chooseEntry();
void resetInputs();
void checkPassword();
void wakeTheStag();
const static int passSize = 2;
static int LED_VCC = 2; //LEDs are powered from this pin
static int entryCount = 0;
//digital pins
static int servoLeft = 9;
static int servoRight = 10;
//analog pins
static int eyes = 17;
static int password[passSize] = {3,5};
static int defPass[2] = {3,4};
static int entry[passSize] = {0,0};
static int runes[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static bool locked = true;
int count = 0;
int index = 0;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
pinMode(14, INPUT);
pinMode(15, INPUT);
pinMode(16, INPUT);
pinMode(17, OUTPUT);
digitalWrite(LED_VCC, HIGH);
}
void loop() {
Serial.print(entry[0]);
Serial.print(entry[1]);
Serial.println("");
Serial.println(entryCount);
if(locked){
checkRunes();
chooseEntry();
checkPassword();
}
}
void checkRunes(){
for(int i = 3; i < 17; i++){
if(i == servoLeft || i == servoRight || i == eyes || i == 18 || i == 19)
runes[i] = 0;
runes[i] = digitalRead(i);
}
}
void chooseEntry(){
for(int i = 3; i < 17; i++){
bool found = false;
for(int j = 3; j < 17; j++){
if(entry[j] == i){
found = true;
break;
}
}
if(!found)
entry[entryCount++] = i;
}
}
void checkPassword(){
for(int i = 0; i < passSize; i++){
if(entry[i] != password[i]){
resetInputs();
return;
}
}
resetInputs();
wakeTheStag();
locked = false;
}
void resetInputs(){
Serial.println("Resetting");
entryCount == 0;
checkRunes();
delay(250);
digitalWrite(LED_VCC, LOW);
delay(250);
digitalWrite(LED_VCC, HIGH);
}
void wakeTheStag(){
digitalWrite(eyes, HIGH);
}
output:
⸮
warning I get when I compile:
C:\Users\x\Documents\Arduino\stag0.3\stag0.3.ino: In function 'void resetInputs()':
C:\Users\x\Documents\Arduino\stag0.3\stag0.3.ino:103:14: warning: statement has no effect [-Wunused-value]
C:\Users\x\Documents\Arduino\stag0.3\stag0.3.ino: At global scope:
C:\Users\x\Documents\Arduino\stag0.3\stag0.3.ino:23:12: warning: 'defPass' defined but not used [-Wunused-variable]