#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte customChar[8] = {
0b11111,
0b10100,
0b10010,
0b10001,
0b10001,
0b10010,
0b10100,
0b11111
};
const int BTN = 7;
int opoPos_x = 15;
int opoPos_y = 0;
int carPos_x = 0;
int carPos_y = 0;
int score = 0;
int speed = 100;
void setup() {
lcd.init();
lcd.backlight();
randomSeed(analogRead(0));
lcd.createChar(0, customChar);
}
void loop() {
opoPos_y = random(0,2);
do{
lcd.clear();
lcd.setCursor(carPos_x, carPos_y);
lcd.write((byte)0);
lcd.setCursor(opoPos_x, opoPos_y);
lcd.print("C");
if(digitalRead(BTN) == HIGH){
carPos_y = 1;
}
else if(digitalRead(BTN) == LOW){
carPos_y = 0;
}
if((carPos_x==opoPos_x)&&(carPos_y==opoPos_y)){
lcd.clear();
lcd.setCursor(2,0);
lcd.print("GAME OVER");
lcd.setCursor(2,1);
lcd.print("SCORE:");
lcd.setCursor(10,1);
lcd.print(score);
delay(5000);
score = 0;
speed = 100;
}
delay(speed);
opoPos_x--;
}while(opoPos_x >= 0);
opoPos_x = 15;
score+=1;
if(speed>20){
speed-=3;
}
}