void sureTut() {
int a = millis();//to scale the time without delays
int basSira = sira;//to notice if player move and press button, then the other player's time will start reducing
int s = 1000;//interval of a second
delay(50);//minimum delay to block arduino thinking player pressed button for million times...
while (sira == basSira){
if(sira == 1) {//if turn is player 1's
if(dakika1<0) {//detect when time is gone and reset clock
dakika1 = 0;
saniye1 = 0;
sureGoster();
lcd.write("Bitti");
delay(5000);
kurulum();
return;
}
if((millis() - a) >= s) {//detect a second
a = millis();//reset variable a
saniye1--;//reduce second
if (saniye1 < 1) {//detect if second goes under 1
saniye1 = 59;//make second 59
dakika1--;//reduce minutes
}
}
} else { // same with other player
if(dakika0<0) {
dakika0 = 0;
saniye1 = 0;
sureGoster();
lcd.write("Bitti");
delay(5000);
kurulum();
return;
}
if((millis() - a) >= s) {
a = millis();
saniye0--;
if (saniye0 < 1) {
saniye0 = 59;
dakika0--;
}
}
}
if(digitalRead(A0)){//to detect button pressed and the other player's turn
sira = 1;
saniye0 += modlarA[mod-1]; //To increase second by a chess rule for example: 5+5 means 5 minutes in start and then increase second by 5 when a player moved
if(saniye0 >= 60) {//if increasing time is bigger than 60 and increase minute
saniye0 -= 60;
dakika0++;
}
sureTut();//restart function
delay(100);
return;//quit function
}
if (digitalRead(A2)) { //same
sira = 0;
saniye1 += modlarA[mod-1];
if(saniye1 >= 60) {
saniye1 -= 60;
dakika1++;
}
sureTut();
delay(100);
return;
}
sureGoster();//to update 2x16 lcd
}
}
I'm trying to make a chess clock but I can't solve this bug:
When time of any player reduces under 30 seconds the time is accelerating.
Thanks in advance!