#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C a(0x27,20,4);
bool test1 = true;
bool test2 = true;
bool test3 = true;
bool casovac = true;
long int cas = 0;
int cislo;
int kde_je_gulicka;
int body;
int cursor = 19;
int pocet[] = {4,8,12,16};
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
a.init();
a.backlight();
randomSeed(analogRead(A0));
rst();
}
void loop() {
a.setCursor(0,3);
a.print("body:");
a.print(body);
a.println(" ");
cursorPlus();
cursorMinus();
potvrd();
if(millis() >= cas){
if(casovac == true && cursor > 0){
a.setCursor(cursor,0);
cursor--;
a.print(" ");
}
else if(cursor == 0 && casovac == true){
body--;
rst();
}
cas += 300;
}
}
void rst(){
a.clear();
cursor = 19;
cislo = 0;
for(int i = 4 ; i < 20; i+=4){
a.setCursor(i,2);
a.print("*");
}
a.setCursor(4,1);
a.println("v");
a.setCursor(0,0);
for(int i = 0 ; i < 20 ; i++){
a.print("#");
}
kde_je_gulicka =random(0,4);
Serial.println(kde_je_gulicka);
delay(300);
}
void cursorPlus(){
if(digitalRead(2) == LOW && test1 == true){
cislo++;
a.setCursor(0,1);
a.print(" ");
if (cislo > 3){
cislo = 0;
}
a.setCursor(pocet[cislo],1);
a.println("v");
test1 = false;
}
else if(digitalRead(2) == HIGH && test1 == false)
{
test1 = true;
}
}
void cursorMinus(){
if(digitalRead(3) == LOW && test2 == true){
cislo--;
a.setCursor(0,1);
a.print(" ");
if (cislo < 0){
cislo = 3;
}
a.setCursor(pocet[cislo],1);
a.println("v");
test2 = false;
}
else if(digitalRead(3) == HIGH && test2 == false)
{
test2 = true;
}
}
void potvrd(){
if(digitalRead(4) == LOW && test3 == true){
if(kde_je_gulicka == cislo){
body++;
Serial.println("si borec");
}
else{
Serial.println("skus znovu");
body--;
}
rst();
test3 = false;
}
else if(digitalRead(4) == HIGH && test3 == false)
{
test3 = true;
}
}