#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int buzPin = 5;
int pushButton = 4;
bool failTry = false;
void setup()
{
DDRB = 0xFF;
PORTB = 0x00;
Serial.begin(9600);
pinMode(buzPin , OUTPUT);
pinMode(pushButton, INPUT_PULLUP);
lcd.backlight();
lcd.init(); //intialize the LCD
lcd.setCursor(2, 0); //set the cursor to Column 3, Row 1
lcd.print("Welcome"); //Print a message to the LCD.
delay(1000);
lcd.setCursor(0, 1); //set the cursor to Column 3, Row 2
lcd.print("Start your game"); //Print a message to the LCD.
delay(1000);
}
void loop()
{
if(digitalRead(pushButton) == LOW) {
failTry = true;
if(PORTB == 0) {
PORTB = 0x01;
} else {
PORTB = PORTB << 1;
}
digitalWrite(buzPin,HIGH );
}
delay(200);
digitalWrite(buzPin, LOW);
if(PORTB == 0) {
lcd.clear();
}
if(failTry) {
if(PORTB == 0x01) {
lcd.clear();
lcd.print(" First Try ");
failTry = false;
} else if(PORTB == 0x02) {
lcd.clear();
lcd.print(" Second Try");
failTry = false;
} else if(PORTB == 0x04) {
lcd.clear();
lcd.print(" Third Try");
failTry = false;
} else if(PORTB == 0x08) {
lcd.clear();
lcd.print("End of game");
lcd.setCursor(0,1);
lcd.print("Try again");
failTry = false;
lcd.setCursor(0,0);
delay(2000);
PORTB = 0;
}
}
// if (currentButtonState==1)
// {
// delay(200);
// Serial.println(currentButtonState);
// buttonState = digitalRead(pushButton);
// }
// if (buttonState == 0)
// {
// //currentButtonState++;
// }
// else if (currentButtonState== 1 )
// {
// digitalWrite(rPin, HIGH);
// digitalWrite(gPin, LOW);
// digitalWrite(bPin,LOW);
// digitalWrite(yPin,LOW);
// tone (buzPin ,3000 ,200) ;
// lcd.setCursor(2 ,0);
// lcd.print(" first trial");
// delay(500);
// }
// else if (currentButtonState== 2 )
// {
// digitalWrite(rPin, LOW);
// digitalWrite(gPin, HIGH);
// digitalWrite(bPin,LOW);
// digitalWrite(yPin,LOW);
// tone (buzPin , 500 , 200) ;
// lcd.setCursor(2 ,0);
// lcd.print(" Second trial");
// delay(500);
// }
// else if (currentButtonState==3)
// {
// digitalWrite(rPin, LOW);
// digitalWrite(gPin, LOW);
// digitalWrite(bPin,HIGH);
// digitalWrite(yPin,LOW);
// tone (buzPin , 500 , 200) ;
// lcd.setCursor(2 ,0);
// lcd.print(" Third trial");
// delay(500);
// }
// else if (currentButtonState==4)
// {
// digitalWrite(rPin, LOW);
// digitalWrite(gPin, LOW);
// digitalWrite(bPin,LOW);
// digitalWrite(yPin,HIGH);
// tone (buzPin , 500 , 200) ;
// lcd.setCursor(2 ,0);
// lcd.print(" WELL DONE");
// delay(500);
// }
// else if (currentButtonState==5)
// {
// currentButtonState=0;
// digitalWrite(rPin, LOW);
// digitalWrite(gPin, LOW);
// digitalWrite(bPin,LOW);
// digitalWrite(yPin,LOW);
// lcd.setCursor(2 ,0);
// lcd.print(" END GAME");
// delay(500);
// }
}