Hello, I'm currently working on this project. The objective it's introduce values with a keypad and save it in the array 'r[3][6]', then when i press the key 'S' it will compare the values of the internal clock with the array values, it works like a chronometer.
Using the code without comparing values array-time, the serial port shows me that this part is working okay. Like the first picture.
But when it try to compare the values that the user introduced with the real time of the internal clock doesn't work, it's shown in the second picture. For me the logic it's okay, but i don't if this could be possible.
Here is the code:
#include <Time.h>
#include <TimeLib.h>
#include <Keypad.h>
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1', '2', '3'},
{'4', '0', 'S'},
{'7', '8', '9'},
{'E', '0', 'S'}
};
byte row[rows] = {13,12,11,10};
byte col[cols] = {9,8,7};
Keypad keypad =Keypad(makeKeymap(keys), row, col, rows, cols);
int r[3][6];
int i=0, a=0, c=0, u=0;
char j, z;
int h=0;
int m=00;
int s=00;
int n, hd, hu, H, md, mu, M, sd, su, S;
void setup() {
Serial.begin(9600);
setTime(h, m, s, 0, 0, 0);//hora, minutos, segundos, dia, mes,año
pinMode(3,OUTPUT);
}
void loop() {
char key =keypad.getKey();
time_t t = now();
//Adding values
if(key!=NO_KEY){
n=num(key);
Serial.print(n);
r*[a] = n;*
-
i++;*
-
a++;*
-
j++;*
-
if (j==2)*
-
{*
-
Serial.print(":");*
-
}*
-
if(j==4){*
-
Serial.print(":");*
-
}*
-
if(j==6){*
-
Serial.println();*
-
j=0;*
-
}*
-
delay(500);*
-
}*
-
if(key =='S'){*
-
delay(10);*
-
u++;*
-
}*
-
//Comparing values*
-
if(u==1){*
-
//Horas*
-
hd =((r*
```c
*[0])*10);
hu =((r[c][1])*1);
H=hd+hu;
//Minutos
md =((r[c][2])*10);
mu =((r[c][3])*1);
M=md+mu;
//Segundos
sd =((r[c][4])*10);
su =((r[c][5])*1);
S=sd+su;
if(H==hour(t) && M==minute(t) && S==second(t)){
digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);
delay(1000);
digitalWrite(3,HIGH);
delay(1000);
digitalWrite(3,LOW);
delay(1000);
c++;
}
if(c==3){
c=0;
u=0;
}
}
}
char num(char z){
int result;
switch(z){
case '1':
result=1;
break;
case '2':
result=2;
break;
case '3':
result=3;
break;
case '4':
result=4;
break;
case '5':
result=5;
break;
case '6':
result=6;
break;
case '7':
result=7;
break;
case '8':
result=8;
break;
case '9':
result=9;
break;
case '0':
result=0;
break;
}
return result;
}
*
```