#include <LiquidCrystal_I2C.h>
byte character[8]{
B11111,
B10101,
B10101,
B11111
};
byte block[8]{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte goal[8]{
B00001,
B00001,
B00001,
B00001,
B000001,
B11111,
B11111,
B11111
};
byte finishchar[8]{
B11111,
B10101,
B10101,
B11111,
B00001,
B11111,
B11111,
B11111
};
LiquidCrystal_I2C lcd(0x27, 16, 2);
int x=0;
int y=0;
//порты подключения кнопок
const int buttonLeft = 6;
const int buttonRight = 8;
const int buttonJump = 7;
int jumpTime=0;
bool isJumping = false;
void setup() {
// запускаем лсд
lcd.init();
lcd.backlight();
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(0, character);
lcd.createChar(1, block);
lcd.createChar(2, goal);
lcd.createChar(3, finishchar);
pinMode(buttonLeft, INPUT_PULLUP);
pinMode(buttonRight, INPUT_PULLUP);
pinMode(buttonJump, INPUT_PULLUP);
}
void loop() {
lcd.clear();
lcd.setCursor(x,y);
lcd.write(byte(0));
lcd.setCursor(15, 0);
lcd.write(byte(2));
if(x==15 && y==0){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("YOU WIN!");
delay(2000);
lcd.clear();
int x=0;
int y=0;
}
if(digitalRead(buttonLeft)==LOW && x>0){
x--;
delay(100);
}
if(digitalRead(buttonRight)==LOW && x<15){
x++;
delay(100);
}
if(digitalRead(buttonJump)==LOW && ! isJumping){
isJumping = true;
jumpTime=0;
}
if(isJumping)
{
if (jumpTime <2){
y=1;
}else if(jumpTime <4){
y=0;
}else{
jumpTime= false;
}
jumpTime ++;
}
delay(2000);
}