Hello, after long research in internet finally I putted together all resources and made scorebaord with lc, keypad and arduino.
Scoreboard can:
- Display countdown and @ the end play buzzer
- Display period and scores for home team and guest
Controls:
A: +1 HOME Score;
B: +1 GUEST SCORE;
C; + 1 PERIOD;
D; period.
And other features like if time goes then green light flash if stops red light flash.
Code not 100% mine, and fixed and converted it to 16x2 display. Maybe someone will use it.
Sorry for english and thank you for your spent time.
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
int controlPin = 13;
char currentTimeValue[4];
int currentState = 1;
int timerSeconds = 0;
int lpcnt = 0;
int per = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int buzzer = A0;
const byte rows = 4;
const byte cols = 4;
int hs = 0;
int gs = 0;
char keys[rows][cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[rows] = {A4,A5,13,10}; //Rows 0 to 3
byte colPins[cols]= {9,8,7,6}; //Columns 0 to 3
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
void setup()
{
pinMode(A1, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
//display main screen
displayCodeEntryScreen();
//setup and turn off relay
pinMode(controlPin, OUTPUT);
digitalWrite(controlPin, LOW);
//setup default time to 00:00
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentTimeValue[3]='0';
showEnteredTime();
digitalWrite(A1, HIGH);
digitalWrite(A3, LOW);
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
}
void loop()
{
while(digitalRead(somePin) == HIGH) { };
int l;
char tempVal[3];
char key = keypad.getKey();
int availableBytes = Serial.available();
if ((String)key == "A"){
hs++;
}
if ((String)key == "B"){
gs++;
}
if ((String)key == "C"){
per++;
}
if ((String)key == "D"){
tone(buzzer, 1000);
delay(900);
noTone(buzzer);
}
//key pressed and state is 1
if (int(key) != 0 and currentState == 1) {
switch (key) {
case 'D':
break;
case '*':
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(7,0);
lcd.print(per);
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
relayStatus(false);
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentTimeValue[3]='0';
showEnteredTime();
currentState = 1;
lpcnt = 0;
timerSeconds = 0;
digitalWrite(A1, HIGH);
digitalWrite(A2, LOW);
break;
case '#':
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(7,0);
lcd.print(per);
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
tempVal[0] = currentTimeValue[0];
tempVal[1] = currentTimeValue[1];
tempVal[2] = 0;
timerSeconds = atol(tempVal) * 60;
tempVal[0] = currentTimeValue[2];
tempVal[1] = currentTimeValue[3];
tempVal[2] = 0;
timerSeconds = timerSeconds + atol(tempVal);
currentState = 2;
digitalWrite(A1, LOW);
digitalWrite(A3, HIGH);
break;
default:
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(7,0);
lcd.print(per);
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
currentTimeValue[0] = currentTimeValue[1];
currentTimeValue[1] = currentTimeValue[2];
currentTimeValue[2] = currentTimeValue[3];
currentTimeValue[3] = key;
showEnteredTime();
break;
}
}
if (currentState == 2) {
if (int(key) != 0) {
if (key == '*') {
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(7,0);
lcd.print(per);
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
relayStatus(false);
displayCodeEntryScreen();
currentTimeValue[0]='0';
currentTimeValue[1]='0';
currentTimeValue[2]='0';
currentTimeValue[3]='0';
showEnteredTime();
currentState = 1;
lpcnt = 0;
timerSeconds = 0;
digitalWrite(A1, HIGH);
digitalWrite(A2, LOW);
}
} else {
if (lpcnt > 9) {
lpcnt = 0;
--timerSeconds;
showCountdown();
if (timerSeconds <= 0) {
for (int a = 0; a<= 1; a++){
tone(buzzer, 1000);
delay(900);
noTone(buzzer);
}
currentState = 1;
relayStatus(false);
displayCodeEntryScreen();
showEnteredTime();
} else {
relayStatus(true);
}
}
++lpcnt;
delay(100);
}
}
}
void showEnteredTime()
{
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(7,0);
lcd.print(per);
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
lcd.setCursor(5,1);
lcd.print(currentTimeValue[0]);
lcd.print(currentTimeValue[1]);
lcd.print(":");
lcd.print(currentTimeValue[2]);
lcd.print(currentTimeValue[3]);
}
void relayStatus(bool state)
{
if (state)
digitalWrite(controlPin, HIGH);
else
digitalWrite(controlPin, LOW);
}
void showCountdown()
{
digitalWrite(A1, LOW);
digitalWrite(A3, HIGH);
lcd.clear();
lcd.setCursor(1,0);
char timest[6];
lcd.setCursor(1,0);
lcd.print("H");
lcd.setCursor(7,0);
lcd.print(per );
lcd.setCursor(1,1);
lcd.print(hs);
lcd.setCursor(14,0);
lcd.print("G");
lcd.setCursor(14,1);
lcd.print(gs);
lcd.setCursor(5,1);
sprintf(timest, "%2d:%.2d", (timerSeconds/60), (timerSeconds - ((timerSeconds/60)*60)));
lcd.print(timest);
}
int availableBytes = Serial.available();
void displayCodeEntryScreen()
{
for(int i=0; i<availableBytes; i++)
{
currentTimeValue[i] = Serial.read();
}
clearScreen();
lcd.setCursor(0,0);
}
void clearScreen()
{
lcd.clear();
}
IMAGE: Screenshot by Lightshot