#include <neotimer.h>
#include <LiquidCrystal.h>
int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonUp = 10;
int buttonDown = 9;
int score = 0;
bool clicked = false;
bool GameOver = false;
int timeLeft = 30;
Neotimer mytimer = Neotimer(1000);
void gameOver(int currentScore)
{
GameOver = true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Game over!");
lcd.setCursor(0, 1);
lcd.print("Your score was: ");
lcd.setCursor(16, 1);
lcd.print(score);
lcd.setCursor(0, 3);
lcd.print("Hold to restart");
delay(3000);
if (digitalRead(buttonDown) == LOW) {
GameOver = false;
timeLeft = 30;
score = 0;
}
}
void setup()
{
Serial.begin(9600);
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
analogWrite(6,Contrast);
lcd.begin(20, 4);
lcd.clear();
mytimer.start();
}
void loop()
{
lcd.clear();
if (mytimer.done()) {
if (timeLeft == 0) {
gameOver(score);
} else {
timeLeft--;
mytimer.start();
}
}
if (!GameOver) {
lcd.setCursor(0, 0);
lcd.print("Time left: ");
lcd.setCursor(11, 0);
lcd.print(timeLeft);
lcd.setCursor(0, 1);
lcd.print("Score: ");
lcd.setCursor(7, 1);
lcd.print(score);
if (digitalRead(buttonDown) == LOW) {
if (clicked == false) {
clicked = true;
score++;
}
} else if (digitalRead(buttonDown) == HIGH) {
clicked = false;
}
}
delay(20);
}