#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int bPin = 7;
int wPin = 6;
int mwTime = 30;
int mbTime = 30;
int swTime = 0;
int sbTime = 0;
int time = 10;
int wState =0;
int bState=0;
int n = 11;
int b = 1;
int x = 2;
int z =3;
int song =500;
int pbState = 0;
int pwState = 0;
int count = 30;
boolean wTurn = true;
void setup(){
lcd.begin(16,2);
pinMode(bPin,INPUT);
pinMode(wPin,INPUT);
}
void loop(){
wState = digitalRead(wPin);
bState = digitalRead(bPin);
if(wState==HIGH&&bState==LOW){
lcd.setCursor(7,0);
if(sbTime<10 && sbTime>0){
lcd.setCursor(z,0);
lcd.print("0");
lcd.setCursor(z+1,0);
lcd.print(sbTime);
lcd.setCursor(0,0);
lcd.print(mbTime);
lcd.setCursor(x,0);
lcd.print(":");
delay(time);
sbTime--;
pwState =wState;
}
else if(sbTime>=10){
lcd.noCursor();
lcd.setCursor(z,0);
lcd.print(sbTime);
lcd.setCursor(0,0);
lcd.print(mbTime);
lcd.setCursor(x,0);
lcd.print(":");
delay(time);
sbTime--;
pwState = wState;
}
else if(sbTime<=0){
lcd.setCursor(z,0);
lcd.print("00");
lcd.setCursor(0,0);
lcd.print(mbTime);
lcd.setCursor(x,0);
lcd.print(":");
sbTime = 59;
mbTime--;
delay(time);
pwState = wState;
if(mbTime<10 && mbTime>-1){
x = 1;
z =2;
pwState = wState;
}
else if(mbTime>=10){
x = 2;
z=3;
pwState = wState;
}
else if(mbTime <=-1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Game Over");
lcd.setCursor(0,1);
lcd.print("Black Timed Out");
tone(9,300);
delay(song);
tone(9,500);
delay(song);
tone(9,300);
delay(song);
tone(9,500);
delay(song);
tone(9,300);
delay(song);
tone(9,500);
delay(song);
tone(9,300);
delay(song);
tone(9,500);
delay(song);
noTone(9);
delay(1000000);
}
}
}
else if(bState==HIGH&&wState==LOW){
if(swTime<10 && swTime>0){
lcd.setCursor(14,0);
lcd.print("0");
lcd.setCursor(15,0);
lcd.print(swTime);
lcd.setCursor(n,0);
lcd.print(mwTime);
lcd.setCursor(13,0);
lcd.print(":");
delay(time);
swTime--;
}
else if(swTime>=10){
lcd.setCursor(14,0);
lcd.print(swTime);
lcd.setCursor(n,0);
lcd.print(mwTime);
lcd.setCursor(13,0);
lcd.print(":");
delay(time);
swTime--;
}
else if(swTime<=0){
lcd.setCursor(14,0);
lcd.print("00");
lcd.setCursor(n,0);
lcd.print(mwTime);
lcd.setCursor(13,0);
lcd.print(":");
swTime = 59;
mwTime--;
delay(time);
if(mwTime<10 && mwTime>-1){
n = 12;
}
else if(mwTime>=10){
n = 11;
}
else if(mwTime <=-1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Game Over");
lcd.setCursor(0,1);
lcd.print("White Timed Out");
delay(1000000);
}
}
}
}
I am trying to make an chess clock on my arduino. The long segments of block are used only for the clock counting down. Is there a way to have one or two words like white_clock become those lines of code to save room in my program? And more importantly, the wButton must be held down to start black's time on the lcd, but when the bButton is pushed, white's time immediately starts. I have tried boolean variables for the program but they have not worked, I tested this program with leds instead of the clock blocks and the two variables worked with the skeleton function. Please help, Ben
I will reiterate, this program is supposed to display two values on a chess clock. The values are to count down in seconds and minutes, when the left button(wButton) is pressed the right time(bTime) starts. However, this is not what occurs. When the left(wButton) is pressed, it starts the right clock, but when it is released, the left clock starts again. When the right button is pressed, it starts the left clock until the left button is released like it is supposed to do.